255

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Hamzeh Soboh
  • 7,572
  • 5
  • 43
  • 54
  • kindly refer my updated answer. – RPB Nov 09 '12 at 19:05
  • 6
    btw: the actual word "ellipsized" is made-up. It's called "verbing a noun" and is a common way to form computer jargon. The noun is "ellipse" which I assume you know, and it's made into a verb by adding the "-ize" ending which means "to make into", so you can infer that to "ellipsize" is "to add an ellipse to something". – Michael Edenfield Jun 20 '13 at 15:23
  • 8
    Old spelling mistake, never corrected. The term should actually be "ellipsis". Ellipse is a curve on a plane surrounding two focal points such that a straight line drawn from one of the focal points to any point on the curve. Ellipsis are the three dots. – radley Dec 10 '13 at 01:44
  • Documentation of ellipseSize has missing description, still. – Talha Mar 02 '17 at 09:00
  • @MichaelEdenfield I believe back-forming the noun “_ellipsis_” to the verb “_to ellipse_” is much more reasonable than “_to ellipsize_.” – Константин Ван May 26 '22 at 04:25

10 Answers10

472

You can find documentation here.

Based on your requirement you can try according option.

to ellipsize, a neologism, means to shorten text using an ellipsis, i.e. three dots ... or more commonly ligature , to stand in for the omitted bits.

Say original value pf text view is aaabbbccc and its fitting inside the view

start's output will be : ...bccc

end's output will be : aaab...

middle's output will be : aa...cc

marquee's output will be : aaabbbccc auto sliding from right to left

Raphael Petegrosso
  • 3,870
  • 2
  • 24
  • 27
RPB
  • 16,006
  • 16
  • 55
  • 79
  • Thanks. But I've already read that. It uses the word "ellipsized" where I'm searching about its meaning. The word can't be used in its definition!! Any further explanation please? – Hamzeh Soboh Nov 09 '12 at 18:49
84

In my experience, Ellipsis works only if the 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.

Aldan
  • 674
  • 9
  • 23
Zephyr
  • 6,123
  • 34
  • 33
  • 5
    Actually `android:singleLine` was deprecated since API level 3, so instead use `android:maxLines`. Please note: > if both singleLine and inputType are supplied, the inputType flags will override the value of singleLine. Check out the docs at [R.attr.html#singleLine](https://developer.android.com/reference/android/R.attr.html#singleLine) – Filipe Bezerra de Sousa Sep 08 '16 at 12:24
  • 1
    @AlbertoGaona I've noticed that it doesn't work if android:ellipsize="start" and android:maxLines="2" (or more). I haven't seen any dots at the start although the text was too long. – ka3ak Oct 28 '18 at 08:20
  • This is the correct answer. It worked for me. `maxLines="1"` without `singleLine="true"` didnt work for me. – user882290 Dec 02 '21 at 16:13
19

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 TextView in some way. 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

Aldan
  • 674
  • 9
  • 23
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
10

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.

Sam
  • 86,580
  • 20
  • 181
  • 179
5

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,...
subodh
  • 6,136
  • 12
  • 51
  • 73
5

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.

Aldan
  • 674
  • 9
  • 23
MojAmiri
  • 506
  • 7
  • 8
  • Thank you this solution fixed my problem. The key is `android:layout_width="0dp"` instead of `android:layout_width="wrap_content"`. Note this is applicable because I'm using a `ConstraintLayout`. Also discussed here https://stackoverflow.com/a/48149405/2848676 – Michael Osofsky Jun 10 '19 at 18:54
1

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

 android:ellipsize="marquee"    
ksu
  • 882
  • 1
  • 11
  • 17
1

Set this property to EditText. Ellipsize is working with disable EditText

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

or setKeyListener(null);

Aldan
  • 674
  • 9
  • 23
Mubarak
  • 1,419
  • 15
  • 22
0

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"
0

As it is already mentioned above if there is no enough space for text (due to the size of the layout or set limitation) ellpsize will add ... dots to it.

Here an example: Top: with ellipsize (here it is set to 'end' Bottom: without enter image description here

Konrad
  • 62
  • 5