当我们在TextView
中应用android:ellipsize
时,我想得到TextView
中可见的字符数。假设我有“这是多线的虚拟头条故事标题,这是多线的假顶级故事标题。”文本和我已经在我的"android:ellipsize="end" android:maxLines="2""
中设置Textview
这些属性,因此它将减少一些文本并显示3个点。现在我想要可见的字符数量。
TextView
的情况下:
stringLength - textView.length()会给出在设备中没有显示或删除多少文本。
TextView
的情况下,您可以使用相同的方式:
布局textViewLayout = textview.getLayout();
textViewLayout.getEllipsisCount(textViewLayout.getLineCount() - 1)getEllipsisCount(int line)
Returns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place.
注意:在textview可见/绘制后必须使用getEllipsisCount
。