TableLayout表格布局
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_tablelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.axnet.buju0711.Tablelayout">
<!--表格布局-->
<Button
android:text="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:text="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:text="3"
android:layout_width="200dp"
android:layout_height="wrap_content"
/>
</TableLayout>
layout_width默认设置match_parent,即使这是200dp也是match_parent
宽度是不可以自己设置的,但是高度是可以自己设置的
显然,一列多行并不能满足大家的需求
这时候就出现了
<TableRow>
把button123放入TableRow中
每个TableRow代表一行
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_tablelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.axnet.buju0711.Tablelayout">
<!--表格布局-->
<TableRow>
<Button
android:text="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:text="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:text="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableRow>
</TableLayout>
加入TableRow以后,我们修改
<Button
android:text="1"
android:layout_width="150dp"
android:layout_height="150dp"
/>
**发现修改一个的宽度,一列的宽度都是变化的,
修改高度,只有修改的控件高度会变化**
android:stretchColumns拉伸
android:layout_span合并行
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_tablelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.axnet.buju0711.Tablelayout">
<!--表格布局-->
<TableRow>
<Button
android:text="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
/>
<!--<Button-->
<!--android:text="2"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--/>-->
<Button
android:text="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableRow>
<TableRow>
<Button
android:text="4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:text="5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
/>
<!--<Button-->
<!--android:text="6"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--/>-->
</TableRow>
<TableRow>
<Button
android:text="7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:text="8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:text="9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableRow>
</TableLayout>
layout_span必须要有相对的参照物才能起作用
如何使每个横行占满屏幕
android:stretchColumns拉伸
//拉伸第三列
android:stretchColumns="2"
android:stretchColumns="*"
拉伸全部列
———-*
如果之拉伸第二三列
android:stretchColumns=”1,2” 用英文逗号分开
如果想要控件居中或者占满整个一行单元格
<TableRow>
<Button
android:text="10"
android:layout_column="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableRow>
<TableRow>
<Button
android:text="11"
android:layout_span="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableRow>
**TableLayout合并单元格只可以合并行
不可以合并列**