android:ellipsize - Add an ellipsis(...) in a TextView

How to Add an ellipsis in a TextView

android:ellipsize added in API Level 1
android: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 (...)

6. Compile and run!