SoFunction
Updated on 2025-03-01

Android method to set TextView to display specified numeric characters, and the part exceeds the... (ellipsis)

This article describes the method of setting the TextView to display a specified numeric character in Android, and displaying... (ellipsis) in more than part. Share it for your reference, as follows:

1. Question:

Today I encountered a demand in the company; TextView settings display up to 8 characters, and the more than part of it will be displayed... (ellipsis)

2. Solution:

I have found a lot of information online. Some people say that I set the android:signature="true" of TextView and android:ellipsize="end" respectively; but I tried it but it was not successful. Finally, I tried it out a method myself as follows: For your reference

<TextView
android:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxEms="18"
android:singleLine="true"
android:ellipsize="end"
/>

That is: this function is achieved by combining android:maxEms and android:singleLine attributes.

For more information about Android related content, please check out the topic of this site:Android development introduction and advanced tutorial》、《Android Service Component Usage Tips Summary》、《Summary of the usage of basic Android components"and"Android control usage summary

I hope this article will be helpful to everyone's Android programming design.