Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 985
michael Avatar asked May 27 '10 17:05

michael


1 Answers

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:

Check if textview is ellipsized in android

like image 200
Santiago Carrillo Avatar answered Sep 21 '22 22:09

Santiago Carrillo