一、Java代码实现 TableLayout自适应屏幕宽度
TableLayout table = new TableLayout(this); table.setStretchAllColumns(true);
二、xml 布局
<?xml version="1.0" encoding="utf-8" ?>
- <!-- 每一列等宽度的拉伸至最大宽度:使用的是在tableLayout中加stretchColumns="*"
-->
- <TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="*" xmlns:android="http://schemas.android.com/apk/res/android">
- <TableRow android:orientation="horizontal">
<EditText android:id="@+id/edit1" android:layout_width="fill_parent" android:layout_height="wrap_content" />
</TableRow>
- <TableRow>
<Button android:id="@+id/but1" android:text="7" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:id="@+id/but2" android:text="8" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:id="@+id/but3" android:text="9" android:layout_width="wrap_content" android:layout_height="wrap_content" />
"
</TableRow>
- <TableRow>
<Button android:id="@+id/but4" android:text="4" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:id="@+id/but5" android:text="5" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:id="@+id/but6" android:text="6" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
TableLayout table = new TableLayout(this); table.setStretchAllColumns(true);
二、xml 布局
<?xml version="1.0" encoding="utf-8" ?>
- <!-- 每一列等宽度的拉伸至最大宽度:使用的是在tableLayout中加stretchColumns="*"
-->
- <TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="*" xmlns:android="http://schemas.android.com/apk/res/android">
- <TableRow android:orientation="horizontal">
<EditText android:id="@+id/edit1" android:layout_width="fill_parent" android:layout_height="wrap_content" />
</TableRow>
- <TableRow>
<Button android:id="@+id/but1" android:text="7" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:id="@+id/but2" android:text="8" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:id="@+id/but3" android:text="9" android:layout_width="wrap_content" android:layout_height="wrap_content" />
"
</TableRow>
- <TableRow>
<Button android:id="@+id/but4" android:text="4" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:id="@+id/but5" android:text="5" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:id="@+id/but6" android:text="6" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</TableRow>
</TableLayout>