简体   繁体   中英

How to calculate count of chars in TextView Android?

I have the following task:

There is string, and it may have any length: from 1 to 50 symbols . And there is TextView for storing this string.

I need to do the following thing:

if TextView can store this string without transferring to next line than TextView should store string, but if string is very large than TextView ,the string should be appended with some chars "..." and shown in textview .

For example,if the string is "abdcdereweewew" and TextView can contain only 10 symbols on one line, then TextView should show "abdcder...". How can I calculate it? Thank you in advance.

You can actually do this by setting the XML-attribute ellipsize on the actual TextView!

android:ellipsize="end"

You should probably also set:

android:singleLine="true"

There are more options with ellipsize, have a look =)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM