2011-05-31 71 views
0

作为标题的含义,我希望我的tablelayout能够均匀分配每列的宽度,并且每列的子项都位于列的中心。但是,也设置android:stretchColumns="*",在每列内拉伸子。Android - 如何在不扩展子项的情况下扩展Tablelayout的列

黑客入侵此问题的任何想法?

使用水平的LinearLayout模仿tablerow的是可以接受的,但我也有不知道如何获得的LinearLayout均匀地安排其子女:(

请帮助, 在此先感谢。

回答

0

没有破解需要。:-) 只需将孩子的layout_width设置为wrap_content而不是fill_parent,或设置为固定值。将layout_gravity设置为center或center_horizo​​ntal。

编辑:添加代码。

试试这个:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:shrinkColumns="*" android:stretchColumns="*"> 
    <TableRow> 
     <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/hello" 
       android:gravity="center" 
       /> 
     <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/hello" 
       android:gravity="center" 
       /> 
     <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/hello" 
       android:gravity="center" 
       /> 
    </TableRow> 
</TableLayout> 
+0

它似乎为我工作,查看详细的任何例子吗? – user718146 2011-05-31 14:01:22

+0

它对我有用。 :-)我用代码更新了我的答案。 – DKIT 2011-06-01 08:45:11

+0

感谢您的回复,我很抱歉,我仍然无法使用它,使用Button小部件而不是Textview :( – user718146 2011-06-01 11:16:32

相关问题