Align textview columns vertically when using custom adaptor / layoutinflator
I have three columns that I want to align vertically. The data for the columns are retrieved using an object and then displayed using a LayoutInflater.
At present the columns are all over the place. I am hoping to have them perfectly aligned. I'm using TextView
but I am starting to wonder if I shouldn't be using some kind of TableLayout.
Here is the XML:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/table_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TableRow android:id="@+id/row_multi_row">
<TextView
android:id="@+id/item1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="3dip"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/item2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="3dip"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/item3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="3dip"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
</TableLayout>
Try this :
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row_multi_row"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:id="@+id/item1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.34"
android:padding="3dip"
android:text="asdasd"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/item2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.34"
android:padding="3dip"
android:gravity="center"
android:text="adasd"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/item3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.32"
android:padding="3dip"
android:gravity="center"
android:text="asdasdad"
android:textAppearance="?android:attr/textAppearanceLarge" />
set all textview width and tab row width to fill parent and use layout_weight="1". It will work
链接地址: http://www.djcxy.com/p/5322.html上一篇: 与我的微调者的行动有一个小问题