2012-03-21 62 views
1

我有三列,我想垂直对齐。列的数据使用对象检索,然后使用layoutflator显示。使用自定义适配器/ layoutinflator时,垂直对齐textview列

目前列已遍布各地。我希望让他们完美对齐。我正在使用文本视图,但我开始怀疑我是否不应该使用某种表格布局。

enter image description here

下面是XML:

机器人:ID = “@ + ID/table_layout” 的xmlns:机器人=“http://schemas.android.com/apk/ RES /机器人” 机器人:layout_width = “FILL_PARENT” 机器人: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:textAppearance="?android:attr/textAppearanceLarge"    
    android:padding="3dip"  android:layout_weight="1" 
/> 

<TextView 
    android:id="@+id/item2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"   android:textAppearance="?android:attr/textAppearanceLarge"    
    android:padding="3dip"   android:layout_weight="1"  
/> 

<TextView 
    android:id="@+id/item3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"        android:textAppearance="?android:attr/textAppearanceLarge"    
    android:padding="3dip"  android:layout_weight="1"  
/>  

</TableRow> 
    </TableLayout> 
+0

文本的意见没有被设置为'fill_parent',从而为他们的需要,他们将永远只能拿那么多房间。 – Matthias 2012-03-21 11:50:11

回答

0

将所有textview宽度和制表符行宽设置为填充父级并使用layout_weight =“1”。它将工作

1

enter image description here试试这个:

<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" />