Monday, July 23, 2018

android:ellipsize="end" and android:maxEms not working




I added



android:ellipsize="end"
android:maxEms="8"
android:singleLine="true"


to my TextView with the intention of showing three dots at the end and max text limit of 8 but it's not working. It shows neither the dots nor any text limit.


Answer




Both of your attributes for adding 'the three dots effect' are correct



android:ellipsize="end"
android:singleLine="true"


but the effect happens only when the TextView does not have any free space on the screen to show the text.



To set the limit of the text in TextView you can use




android:maxLength="8"


but it doesn't add the three dots, and as far as I am aware you would have to do it manually.



Something like this



String text = "A bit longer text";
if (text.length() > 8) {
text = text.substring(0, 8) + "...";

}


The android:maxEms is something else than previous, you can read more about it



What is meant by Ems? (Android TextView)


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...