Is there a way to check whether a TextView's text is truncated in my code?
Asked
Active
Viewed 7,277 times
3 Answers
13
You can use method: getEllipsisCount
public static boolean isTextTruncated( String text, TextView textView )
{
if ( textView != null && text != null )
{
Layout layout = textView.getLayout();
if ( layout != null )
{
int lines = layout.getLineCount();
if ( lines > 0 )
{
int ellipsisCount = layout.getEllipsisCount( lines - 1 );
if ( ellipsisCount > 0 )
{
return true;
}
}
}
}
return false;
}
I found the answer at the following related post:

Community
- 1
- 1

Santiago Carrillo
- 612
- 6
- 12
-
2What is the use of param `String text` ? – Akshay Mahajan Nov 09 '17 at 05:15
-
getLayout return null with me – Mahmoud Mabrok Apr 03 '22 at 09:30
0
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

Community
- 1
- 1

vanangelov
- 164
- 2
- 7
0
Don't think so but you can read here to properly handle it if you only want the text to use one line.

Community
- 1
- 1

Robby Pond
- 73,164
- 16
- 126
- 119