如标题所示,我希望我的tablelayout均匀分配每列的宽度,并且每列的子节点在列内居中。但是,设置android:stretchColumns="*"
也会将每个列中的子项拉伸。
任何黑客攻击这个问题的想法?
使用水平Linearlayout模仿一个tablerow是可以接受的,但我也不知道如何让Linearlayout平均排列它的孩子:(
请帮助, 提前谢谢。
答案 0 :(得分:0)
不需要黑客攻击。 :-) 只需将子项的layout_width设置为wrap_content而不是fill_parent,或设置为固定值。将layout_gravity设置为center或center_horizontal。
编辑:代码已添加。
试试这个:
<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>