We all know that by specifying android:ellipsize= "End" android:singleline= "true", you can have TextView automatically truncate the out-of-section and add ellipses. But how do you tell if a textview has been truncated?
This question was discussed on StackOverflow, but unfortunately I tested layout layout = Mytextview.getlayout (); And then I found a better way:
First, customize a subclass of TextView, declaring two methods:
| 1234567891011 |
privateintgetAvailableWidth() { returngetWidth() - getPaddingLeft() - getPaddingRight(); } privatebooleanisOverFlowed() { Paint paint = getPaint(); floatwidth = paint.measureText(getText().toString()); if(width > getAvailableWidth()) returntrue; returnfalse; } |
Then call isoverflowed in the ontextchanged.
Http://www.hankcs.com/program/mobiledev/android-textview-determine-whether-excess-of-ellipsis.html