Is There A Way To Check If A Textview's Text Is Truncated
Is there a way to check whether a TextView's text is truncated in my code?
Solution 1:
You can use method: getEllipsisCount
publicstaticbooleanisTextTruncated( String text, TextView textView )
{
if ( textView != null && text != null )
{
Layoutlayout= textView.getLayout();
if ( layout != null )
{
intlines= layout.getLineCount();
if ( lines > 0 )
{
intellipsisCount= layout.getEllipsisCount( lines - 1 );
if ( ellipsisCount > 0 )
{
returntrue;
}
}
}
}
returnfalse;
}
I found the answer at the following related post:
Check if textview is ellipsized in android
Solution 2:
Don't think so but you can read here to properly handle it if you only want the text to use one line.
Solution 3:
Check out this topic
... You can create a Paint object with TextView2's text size and use breakText() to measure how many characters will fit in your TextView2's width...
It works for me
Post a Comment for "Is There A Way To Check If A Textview's Text Is Truncated"