virtual6
virtual6

Reputation: 35

TextView Ellipsize not working

Below is TextView defined in xml.

     <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="Select Language"
            android:singleLine="true"
            android:maxLines="1"
            android:maxLength="30"
            android:ellipsize="end"
            android:padding="4dp"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="@android:color/holo_blue_dark"
            android:id="@+id/selected_language" />

I want to ellipsize text when text length is greater than 30 chars but its not working at all.please check if i am missing anything.i tried answers posted for similar question but it did not work.

Upvotes: 3

Views: 2844

Answers (3)

virtual6
virtual6

Reputation: 35

Thanks for the answer. i removed the maxLength attribute and set its width to match_parent.its working now.

Upvotes: -1

Sivaranjani
Sivaranjani

Reputation: 56

ellipsize wont work based on the max length it will work width of your textview.

In your code you mention like maxlength 30 so try to specify width of textview.

Upvotes: 2

Divyang Panchal
Divyang Panchal

Reputation: 1909

I have Changed MaxLength to MaxEms in your TextView its Working now use this.

<TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="Select Language"
            android:singleLine="true"
            android:maxLines="1"
            android:maxEms="30"
            android:ellipsize="end"
            android:padding="4dp"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="@android:color/holo_blue_dark"
            android:id="@+id/selected_language" />

Upvotes: 2

Related Questions