2

After a TextView being drawn on the screen, how to determine whether it was ellipsized or not?

TextView -> maxLines = 1 -> ellipsize = end

How to identify if a text was ellipsized or not? Using the texts below, should return true to text 1 and false to text 2.

String on screen

Lorem ipsum dolor sit amet, consectetuer adipiscing...

Sample text 1

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.

Sample text 2

Lorem ipsum dolor sit amet.

Bruno Martins
  • 1,347
  • 2
  • 11
  • 32
  • checkout this thread! https://stackoverflow.com/questions/4005933/how-do-i-tell-if-my-textview-has-been-ellipsized – Helge Mar 02 '19 at 01:29

1 Answers1

1

You can check

Layout layout = textview.getLayout();
if (layout != null) {
    int lines = layout.getLineCount();
    if (lines > 0) {
        if (layout.getEllipsisCount(lines-1) > 0) {
            return true;
        } else
            return false;
    }
}
Nirali
  • 13,571
  • 6
  • 40
  • 53
  • The only missing thing on this solution was that the layout is not prepared at the beginning so is necessary to call it inside the view post: textView.post { /** call logic here**/ } – Bruno Martins Mar 12 '19 at 15:39