Android 如何使表格布局中的列均匀分布以最大程度地利用可用空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2340647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to make columns in table layout spread evenly making maximum use of space available
提问by Amit
I was just trying out with table layout to display some data.... The data is a 3 column data and i want that the columns should utilize the whole width available. But it seems that the layout XML code which i had used is just wrapping up the columns according to the content.
我只是尝试使用表格布局来显示一些数据.... 数据是 3 列数据,我希望这些列应利用可用的整个宽度。但似乎我使用的布局 XML 代码只是根据内容包装列。
Layout XML code
布局 XML 代码
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableRow
android:layout_width="fill_parent">
<TextView
android:padding="3dip"
android:gravity="left"
android:text="Name"
/>
<TextView
android:padding="3dip"
android:gravity="left"
android:text="Address"
/>
<TextView
android:padding="3dip"
android:gravity="left"
android:text="Age"
/>
</TableRow>
</TableLayout>
回答by CommonsWare
You can try adding android:stretchColumns="0,1,2"
to your <TableLayout>
element.
您可以尝试添加android:stretchColumns="0,1,2"
到您的<TableLayout>
元素。
回答by Amit
android:stretchColomns="0,1" is a good option. Also you can try using android:layout_span = "2" This will stretch the columns together depending on your value(Here it will span two columns together)
android:stretchColomns="0,1" 是一个不错的选择。您也可以尝试使用 android:layout_span = "2" 这将根据您的值将列拉伸在一起(这里它将跨越两列)