0

I have the following TextView

<TextView
    android:id="@+id/textView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:maxLines="3"
    android:text="Large text"
    android:ellipsize="end" />

When I calling textView.getLineCount() I always get 3. But I want to get "Real number of lines" which hidden because I'm using maxLines. How can I do that?

Danil
  • 113
  • 1
  • 4

2 Answers2

0

In xml code, add this to TextView:

android:inputType = "textMultiLine"
egbinola
  • 21
  • 4
  • Check this: https://stackoverflow.com/a/29465887/10890095 .. your text should be longer than view for ellipsize to work. – egbinola Jan 31 '19 at 19:43
0

Use TextView.getLayout() to access information about the actual text currently being laid out.

TextView tv = findViewById(R.id.textView);
int realLines = tv.getLayout().getLineCount();
Ben P.
  • 52,661
  • 6
  • 95
  • 123