Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - ellipsize="end" Not Showing Three Dots

I'm working on a TextView which is contained in a ConstraintLayout.

I want ellipsize to add three dots at the end of text(in the TextView) if its length exceeds maxLength.

maxLines="1" and ellipsize="end" seemed to the best answer after a thorough research about my question. Unfortunately, it didn't work for my case. The three dots did't show at all.

Here's the snapshot :

enter image description here

The original string was "Test for long description"(The n was dropped). It's supposed to show "Test for long descrip...".

Here's my xml :

<TextView
    android:id="@+id/txtDescription"
    android:maxLength="24"
    android:maxLines="1"
    android:ellipsize="end"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="120dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="16dp"
    android:layout_marginBottom="8dp"
    android:text="DescriptionView"
    android:textSize="18sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.72" />

I feel like there's something override ellipsize in the XML, or did I miss something crucial in the XML file?

like image 607
Jerry Chen Avatar asked Nov 17 '18 07:11

Jerry Chen


2 Answers

The problem is:

android:maxLength="24"

remove it since you want the TextView to be ellipsized.
A TextView gets ellipsized when it is not wide enough to show the whole text.
I think you do not understand what this attribute android:ellipsize="end" is all about.
If it is wide enough then you will not see any dots at the end because they are not needed.
If you set android:layout_width="40dp" then you will see the dots.
With android:layout_width="wrap_content" the TextView is wide enough and it is not ellipsized.

like image 133
forpas Avatar answered Oct 01 '22 03:10

forpas


1) Add one more property android:singleLine="true" in your Textview

(But its Deprecated so use second option)

2) Use this three together

android:maxLines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
like image 37
Soham Pandya Avatar answered Oct 01 '22 03:10

Soham Pandya