How to Add an ellipsis in a TextView
android:ellipsize added in API Level 1android:scrollHorizontally added in API Level 1
An ellipsis is three periods in a row. (...)
1. Add a TextView to your activity.
2. In the main.xml file, add the below line
<TextView
....
android:text="This is a really, really, really long line of text so you can see how to ellipse works."
android:ellipsize = "end"
/>
3. At this point, the ellipsis will not display yet as a TextView is set to automatically expand on default when new text is entered. You will need to limit the TextView in some way. Do do this, you can use either add to your TextView a scrollHorizontally, minLines, or maxLines to have the ellipsis display.
android:scrollHorizontally = "true"
android:minLines = "2"
android:maxLines = "2"
4. To make the ellipse:
at the end: this is how it would...
use: android:ellipsize = "end"
in the middle: this is ...how it would
use: android:ellipsize = "middle"
at the start: ...this is how it would
use: android:ellipsize = "start"
to have no ellipse
use: android:ellipsize = "none"
5. Do not use android:singeLine = "true", it is deprecated.
android:maxLines = "1" will not display the three dots (...)
android:lines = "1" will not display the three dots (...)
Related Articles:
- Deprecated: android:singleLine Set EditText to One Horizontally Scrolling Line
- android:maxLines - Set the Maximum Viewable Lines of text in a TextView
- android:lines - Change the number of lines of text viewable in a TextView/EditText
http://developer.android.com/reference/android/R.attr.html#ellipsize
http://developer.android.com/reference/android/widget/TextView.html#attr_android:ellipsize