开发者

How to abbreviate a TextView?

开发者 https://www.devze.com 2023-01-17 06:31 出处:网络
I have a TextView that is a single line. How can I add ellipses (...) if the text i开发者_JS百科s too long?In your XML-file you can use: android:ellipsize=\"end\".

I have a TextView that is a single line. How can I add ellipses (...) if the text i开发者_JS百科s too long?


In your XML-file you can use: android:ellipsize="end".

In your .java code you can use: yourTextView.setEllipsize(TextUtils.TruncateAt.valueOf("END"));.

Remember to use it when you want ellipses if the text is reaching its parent's width.


Be aware of some issues by using the function: Android: Something better than android:ellipsize="end" to add "..." to truncated long Strings?

however, its still the most robust way to do it.

0

精彩评论

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