wow
wow

Reputation: 3899

Custom List View - Lining up items

So I have a custom list view set up using an ArrayAdapter, etc. I have that all working fine but this is more of a question about design I suppose.

I have 2 ListViews on each row and I want the margin area to line up on each row as it currently does not when there is a different amount of characters in the first TextView.

Here is an example picture: enter image description here

You can see that the Example 1, 2 and 3 do not line up, I would like to change this so that they can but I cannot figure out how. I have played around with the margins a bit but this does not help. Below is the XML for the row:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/listViewRowItemInitials"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_marginTop="10dp"
        android:gravity="center_vertical"
        android:textSize="12sp" />

    <TextView
        android:id="@+id/listViewRowItemFull"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:gravity="center_vertical"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

Upvotes: 0

Views: 90

Answers (1)

Ken Wolf
Ken Wolf

Reputation: 23269

Just specify a width for the first TextView

<TextView
    android:id="@+id/listViewRowItemInitials"
    android:layout_width="100dp"
    android:layout_height="fill_parent"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="10dp"
    android:gravity="center_vertical"
    android:textSize="12sp" />

Upvotes: 2

Related Questions