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.


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;
  • 1
Reply Report
    • 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: { /** call logic here**/ }

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions