Android -- how to strech columns of Tablelayout without streching its children
as the title means, I want my tablelayout to evenly assign each column's width and the child of each column be ce开发者_StackOverflowntered inside the column. Setting android:stretchColumns="*"
also, however, streches the child inside each column.
any ideas for hacking this issue?
using horizontal Linearlayout to imitate a tablerow is acceptable, but I also have no idea how to get a Linearlayout to arrange its children evenly :(
pls help, thanks in advance.
No hack needed. :-) Simply set the layout_width of the children to wrap_content instead of fill_parent, or to a fixed value. Set layout_gravity to center or center_horizontal.
EDIT: Code added.
Try this:
<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>
精彩评论