I’ve got a ListView with a custom adapter, and I’m trying to modify the layout XML for the list item row so that it looks correct. I’m trying to achieve the following layout (imagine that the below is centered vertically):
Icon Title >
Description
The problem that I’m running into however is that the Title and Description’s are varying lenghts, therefore the “>” icon is pushed more to the right with longer text (and sometimes goes beyond the screen).
I’m trying to get the “>” icon to always be on the far right edge of the screen, and to have any longer text be “capped” with an ellipsis. I’d prefer to not use a RelativeLayout. Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp" >
<ImageView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical"
android:src="@drawable/icon" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/serverName"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:textSize="16sp" />
<TextView
android:id="@+id/description"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingRight="10dp"
android:paddingLeft="15dp"
android:textSize="10sp"
android:singleLine="true"
android:ellipsize="end" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical"
android:gravity="right"
android:src="@drawable/chevron" />
</LinearLayout>
I’d appreciate any help.
Use RelativeLayout to achieve this. Here is an example from android developer blog LINK