[android] What does ellipsize mean in android?

I've added an EditText to my layout, and added a hint, and made it centered horizontally.

When running the application, the hint was invisible. I found that I should make ellipsize value of the TextView to be start:

<EditText
    android:id="@+id/number1EditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="start"
    android:ems="10"
    android:gravity="center_horizontal"
    android:hint="@string/hint1" />

In Android documentation, I read:

If set, causes words that are longer than the view is wide to be
ellipsized instead of broken in the middle.

The problem is that ellipsize is not found in the dictionary. Can anybody explain to me what benefits we can gain by ellipsize attribute? And what is the difference between start, end, middle?

This question is related to android android-layout textview

The answer is


An ellipsis is three periods in a row...

The TextView will use an ellipsis when it cannot expand to show all of its text. The attribute ellipsized sets the position of the three dots if it is necessary.


Set this property to edit text. Elipsize is working with disable edit text

android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
android:singleLine="true"
android:editable="false"

or setKeyListener(null);


Use ellipsize when you have fixed width, then it will automatically truncate the text & show the ellipsis at end,

it Won't work if you set layout_width as wrap_content & match_parent.

android:width="40dp"
android:ellipsize="end"
android:singleLine="true"

android:ellipsize added in API Level 1. An ellipsis is three periods in a row. (...) .

In your Xml

 <TextView
       ....
       android:text="Hi I am Amiyo, you can see how to ellipse works."
       android:ellipsize = "end"  
   />

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.

To make the ellipse:

    at the end: this is how it would.   
    use: android:ellipsize = "end"

And

 in the middle:
 use: android:ellipsize = "middle"

And

 at the start:
 use: android:ellipsize = "start"

And

 to have no ellipse
 use: android:ellipsize = "none"

Note Please :

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 (...)

For more details you can visit here

http://developer.android.com/reference/android/widget/TextView.html#attr_android%3aellipsize


Text:

 This is my first android application and
 I am trying to make a funny game,
 It seems android is really very easy to play.

Suppose above is your text and if you are using ellipsize's start attribute it will seen like this

This is my first android application and
...t seems android is really very easy to play.

with end attribute

 This is my first android application and
 I am trying to make a funny game,...

here is an example on how ellipsize works without using deprecated android:singleLine="true" in a ConstraintLayout:

<TextView
   android:layout_width="0dp"
   android:layout_height="wrap_content"
   android:textSize="13sp"
   android:ellipsize="end"
   android:maxLines="2"
   app:layout_constraintEnd_toEndOf="parent"
   app:layout_constraintStart_toStartOf="parent"
   tools:text="long long long long long long text text text" />

remember if you have a text that is supposed to be in a single line, then change the maxLines to 1.


for my experience, Ellipsis works only if below two attributes are set.

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

for the width of textview, wrap_content or match_parent should both be good.


Note: your text must be larger than the container box for the following to marquee:

 android:ellipsize="marquee"    

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to android-layout

How to check if a key exists in Json Object and get its value How to center the elements in ConstraintLayout Android - how to make a scrollable constraintlayout? Add ripple effect to my button with button background color? This view is not constrained vertically. At runtime it will jump to the left unless you add a vertical constraint Is it possible to put a ConstraintLayout inside a ScrollView? Differences between ConstraintLayout and RelativeLayout How to remove title bar from the android activity? How to have EditText with border in Android Lollipop Android: ScrollView vs NestedScrollView

Examples related to textview

Kotlin: How to get and set a text to TextView in Android using Kotlin? How to set a ripple effect on textview or imageview on Android? The specified child already has a parent. You must call removeView() on the child's parent first (Android) Android: Creating a Circular TextView? android on Text Change Listener Android - Set text to TextView Placing a textview on top of imageview in android Rounded corner for textview in android Different font size of strings in the same TextView Auto-fit TextView for Android