Bruno Martins
Bruno Martins

Reputation: 1446

How to identify if a text was ellipsized or not

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.

Upvotes: 2

Views: 212

Answers (1)

Nirali
Nirali

Reputation: 13825

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;
    }
}

Upvotes: 1

Related Questions