How can I show ellipses on my TextView if it is greater than the 1 line?

Sheehan Alam picture Sheehan Alam · Jun 18, 2011 · Viewed 76.5k times · Source

I have the following Layout which does not work:

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:id="@+id/experienceLayout" 
    android:background="#ffffff" 
    android:layout_height="match_parent" 
    android:paddingLeft="6dp" 
    android:paddingRight="6dp" 
    android:paddingBottom="6dp" 
    android:paddingTop="6dp">

    <TextView 
        android:layout_weight="1" 
        android:id="@+id/experienceLabel" 
        android:text="Experience" 
        android:layout_height="wrap_content" 
        android:textColor="#000000" 
        android:layout_width="wrap_content" 
        android:textStyle="bold">
    </TextView>

    <TextView 
        android:id="@+id/experienceTextView" 
        android:text="TextView" 
        android:layout_height="wrap_content" 
        android:textColor="#000000" 
        android:layout_width="wrap_content" 
        android:ellipsize="end" 
        android:lines="1" 
        android:maxLines="1" 
        android:singleLine="true" 
        android:fadeScrollbars="false">
    </TextView>

</LinearLayout>

Answer

BonanzaDriver picture BonanzaDriver · Jun 18, 2011

This is a common problem. Try using the following:

android:scrollHorizontally="true"
android:ellipsize="end" 
android:maxLines="1"

.............. the scrollHorizontally is the "special sauce" that makes it work.