1

I have the following XML layout for an item that I put in my list view:

 <RelativeLayout·
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:padding="4dp"
 >

   <TextView·
     android:id="@+id/librarySongName"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textAppearance="?android:attr/textAppearanceMedium"
     android:textStyle="bold"
     android:ellipsize="marquee"
     android:scrollHorizontally="true"
     android:lines="1"
     android:layout_alignParentLeft="true"
   />

   <TextView·
     android:id="@+id/libraryArtistName"
     android:layout_gravity="center_vertical"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textAppearance="?android:attr/textAppearanceSmall"
     android:layout_below="@id/librarySongName"
     android:paddingLeft="4dp"
   />

   <ImageButton
     android:id="@+id/lib_add_button"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:minHeight="40dp"
     android:minWidth="40dp"
     android:src="@android:drawable/ic_input_add"
     android:layout_alignParentRight="true"
     android:gravity="center_vertical"
   />

 </RelativeLayout>

However, when I get I get song titles that are too long, my views end up looking like this:

Picture of list view

As you can see there are song titles that just get cutoff rather than being ellipsized correctly. Does anyone know how I can fix this?

Kurtis Nusbaum
  • 30,445
  • 13
  • 78
  • 102

4 Answers4

1
 <TextView·
         android:id="@+id/librarySongName"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textAppearance="?android:attr/textAppearanceMedium"
         android:textStyle="bold" android:layout_toLeftOf="@+id/lib_add_button"
         android:ellipsize="marquee"
         android:scrollHorizontally="true"
         android:lines="1" gravity="left" 
         android:layout_alignParentLeft="true"
       />

here you add android:layout_toLeftOf="@+id/lib_add_button" and gravity="left"

Samir Mangroliya
  • 39,918
  • 16
  • 117
  • 134
0

Set the Padding of the textview librarySongName as :

 android:paddingRight="25dip"
Krishnakant Dalal
  • 3,568
  • 7
  • 34
  • 62
0

give weight or fixed width for TextView and Image Button rather than saying wrap_content... because when you say weight both views take some fixed width.. but when you say wrap_content they take as much space as they want to wrap their content...

ngesh
  • 13,398
  • 4
  • 44
  • 60
0

Try this layout:

 <RelativeLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:padding="4dp"
 >

   <ImageButton
     android:id="@+id/lib_add_button"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:minHeight="40dp"
     android:minWidth="40dp"
     android:src="@android:drawable/ic_input_add"
     android:layout_alignParentRight="true"
     android:gravity="center_vertical"
   />

   <LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_toLeftOf="@id/lib_add_button"
     android:orientation="vertical">

     <TextView
       android:id="@+id/librarySongName"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:textStyle="bold"
       android:ellipsize="marquee"
       android:scrollHorizontally="true"
       android:lines="1"
     />

     <TextView
       android:id="@+id/libraryArtistName"
       android:layout_gravity="center_vertical"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceSmall"
       android:paddingLeft="4dp"
     />
   </LinearLayout>

 </RelativeLayout>

I wrapped the TextViews in a LinearLayout and made it fill the area from the left to the ImageButton at the right.

Jason Robinson
  • 31,005
  • 19
  • 77
  • 131