4

I'm trying to get ellipsize to work for a single line of text inside a TextView. I've already tried all the workarounds (e.g. scrollHorizontally, singleLine, lines, etc.) below previous questions, but nothing seems to happen. This is my code (tested on an HTC One M8 (5.0.1)):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@drawable/file_tile_background" >

<ImageView
    android:id="@+id/file_tile_imageview"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="24dp"
    android:src="@drawable/ic_insert_drive_file_black"
    android:contentDescription="@string/file_tile_imageview_description" />

<TextView
    android:id="@+id/file_tile_textview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@id/file_tile_imageview"
    android:text="@string/file_tile_textview_fileName"
    android:maxLines="1"
    android:ellipsize="start"
    android:textSize="16sp" />
</RelativeLayout>

EDIT: Maybe it doesn't like that I include this layout in activity_main.xml and doesn't use it directly?

David
  • 382
  • 3
  • 10

1 Answers1

3

Simple solution is to use android:singleLine="true".

You can find the related solution on the following link.

TextView's ellipsize not working on maxLines = 1

Community
  • 1
  • 1
Efe Budak
  • 659
  • 5
  • 27