How do I tell if my textview has been ellipsized?

前端 未结 14 1666
天涯浪人
天涯浪人 2020-11-30 19:31

I have a multi-line TextView that has android:ellipsize=\"end\" set. I would like to know, however, if the string I place in there is actually too

14条回答
  •  星月不相逢
    2020-11-30 20:07

    I think the easiest solution to this question is the following code:

    String text = "some looooong text";
    textView.setText(text);
    boolean isEllipsize = !((textView.getLayout().getText().toString()).equalsIgnoreCase(text));
    

    This code assumes that in your XML the TextView set a maxLineCount :)

提交回复
热议问题