4

I need to set ellipsize=end to TextView which is allowed to expand on two lines. I've tried this code:

<TextView
    android:id="@+id/carouselTitle"
    android:layout_width="228dp"
    android:layout_height="40dp"
    android:layout_marginBottom="0dp"
    android:layout_marginLeft="90dp"
    android:layout_marginRight="0dp"
    android:layout_marginTop="4.5dp"
    android:ellipsize="end"
    android:maxLines="2"
    android:textSize="24sp"
    android:textStyle="bold" >
</TextView>

Please reply with an example.

Community
  • 1
  • 1
user1321915
  • 61
  • 1
  • 4

2 Answers2

4
<TextView 
 android:layout_width="fill_parent" 
 android:layout_height="wrap_content" 
 android:ellipsize="marquee" 
 android:singleLine="false" 
 android:maxLines="2"   
 android:text="here is my text" />
Furqi
  • 2,403
  • 1
  • 26
  • 32
3

This one will be work:

<TextView
    android:id="@+id/carouselTitle"
    android:layout_width="228dp"
    android:layout_height="40dp"
    android:layout_marginBottom="0dp"
    android:layout_marginLeft="90dp"
    android:layout_marginRight="0dp"
    android:layout_marginTop="4.5dp"
    android:ellipsize="end"
    android:maxLines="2"
    android:singleLine="false"
    android:textSize="24sp"
    android:textStyle="bold" >
</TextView>

The only thing you missed is android:singleLine="false".

And I recommend to put android:gravity="center_vertical" for better UI. If the text just on one line, it will be center vertically.

KimKha
  • 4,370
  • 1
  • 37
  • 45