I would like my list view items to be lined up and appear as tabular data. I have four TextViews in each ListItem. I have the 1st and 4th even on the edges. I can not get the middle to line up. Is there a better way to do this?
<?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="40dp"
android:background="@color/row_selector"
android:paddingLeft="10dp"
android:paddingRight="5dp"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:id="@+id/labelGas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="25"
android:text="@+id/label"
android:textColor="#222"
>
</TextView>
<TextView
android:id="@+id/labelDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="15"
android:text="@+id/label"
android:textColor="#222"
>
</TextView>
<TextView
android:id="@+id/labelApr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="35"
android:text="@+id/label"
android:textSize="18dp" >
</TextView>
<TextView
android:id="@+id/labelFee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
android:text="@+id/label"
>
</TextView>
</LinearLayout>
If you set
android:layout_width="0dp"for all the TextView tags, then the views will have widths exactly according to the weights, regardless of their actual content.