开发者

Measure text length before rendering

开发者 https://www.devze.com 2023-02-04 17:38 出处:网络
I have a widget where I need to display some text on one row. If the text does not fit, I wo开发者_JAVA百科uld like to show as much as possible and end the text with \"...\" to show that not all text

I have a widget where I need to display some text on one row. If the text does not fit, I wo开发者_JAVA百科uld like to show as much as possible and end the text with "..." to show that not all text is displayed. Is there a way to discover how long the displayed text will be before rendering the widget, so that I can replace the last part of the text with "..."?

Cheers,


You don't need to do that - a TextView can do it for you.

myTextView.setSingleLine(true);
myTextView.setEllipsize(TextView.TruncateAt.END);
0

精彩评论

暂无评论...
验证码 换一张
取 消