1

I want to get the number of characters which are visible in TextView when we have applied android:ellipsize in TextView. Suppose i have "This is dummy top stories title with multiline, This is dummy top stories title with multiline." text and i have set "android:ellipsize="end" android:maxLines="2"" these properties in my Textview , so it will cut down some text and show the 3 dots. Now i want the nuumber of characters which are visible.

1 Answers1

0
  • In case of singleLine TextView:

    stringLength - textView.length()

would give how much text is not shown or ellipsized away in device.

  • Same way in case of multiline TextView you can use:

    Layout textViewLayout = textview.getLayout();

    textViewLayout.getEllipsisCount(textViewLayout.getLineCount()-1)

As per Documentation at developer.android.com

getEllipsisCount(int line)

Returns the number of characters to be ellipsized away, or 0 if no ellipsis is to take place.

Note: getEllipsisCount must be used after textview is visible/drawn.

Er. Kaushik Kajavadara
  • 1,657
  • 2
  • 16
  • 37