Skip to content Skip to sidebar Skip to footer

How To End Textview With 3 Dots By Using Maxlength

I have a TextView in my layout which is wrap_content in layout_width. It is limited to maximum of 15 characters so I'm using maxLength. I need to end this TextView with 3 dots (...

Solution 1:

This will solve your problem, Use ellipsize Property in your XML Code

android:ellipsize="end" <!-- This makes the magic ... thing -->
android:maxEms="15" <!-- Limit of the Text -->
android:singleLine="true" <!-- In case if you want everything in one line -->

Edit:singleLine is deprecated. Use maxlines="1" instead.

Solution 2:

You cannot use both maxLength and Ellipsize although you can define Maximum EMS see the example below

<TextView
        android:id="@+id/tv_hist_source_lang"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:maxEms="8"
        android:maxLines="1"
        android:text="TextView"
        android:textAppearance="?android:attr/textAppearanceMedium" />

It looks like this

Solution 3:

I gather (from comment) that @Yaniv already solved it using code - but this is the right way to do it (with xml). May help other users who land here. Trick is to use both toleftof and torightof.

<RelativeLayout>
...
 <TextViewandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:singleLine="true"android:layout_toRightOf="@id/some_element1"android:layout_toLeftOf="@id/some_element2"/>
...
<RelativeLayout>

Solution 4:

You can use

android:maxWidth="100dp"android:maxLines="1"android:ellipsize="end"

Only this works for me.

Solution 5:

use this android:ellipsize="end"

Post a Comment for "How To End Textview With 3 Dots By Using Maxlength"