Add an ellipsis in a TextView Android

Ellipsis is triple dots (...) at the end of the line. It is required when you want to keep your sentence in a single line. If your test reached the end of the line then automatically create ... at the end.

Steps to create ellipsis TextView in android:

1. Add TextView in your activity.

<TextView
    android:id="@+id/txtShortMessage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry."
/>

Above is the normal textview for displaying text.

2. Set code for ellipsis:

<TextView
    android:id="@+id/txtShortMessage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry."

    android:scrollHorizontally="true"
    android:ellipsize="end" 
    android:maxLines="1"
/>

You can use android:ellipsize="start" or   android:ellipsize="middle" according your need.

3. Run the app and view output.

Keywords: