Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TextVIew Ellipsis based on view size

I'm trying to set ellipsis to the end of my text(multi-line) if the text is too long.

I already know I can use setMaxLines() and setEllipsize() to achieve the effect. However, since my textview's size is dynamically changeable, I don't know the max number of lines that can be displayed. Instead I have the textview's height (by pixel).

How do I set ellipsis based on the height of the view and the text(includes font properties)? If no direct available resource I can use, what could be the easiest possible approach?

like image 498
yongsunCN Avatar asked Dec 02 '25 18:12

yongsunCN


1 Answers

You can use getLineCount() (but only after a layout pass).

See this answer for more information.

like image 119
Buddy Avatar answered Dec 04 '25 07:12

Buddy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!