表格布局---(TableLayout)
TableLayout 类以行和列形式管理控件,每行为一个TableRow对象,也可以为View对象,
当为View 对象时,该View对象将跨越该行的所有列,在TableRow 中也可以添加子空间,
每添加一个子空间为一列;
在TableLayout中,可以设置三种属性:
* Shrinkable ,该列的宽度可以进行收缩,以使表格能够适应其父容器的大小;
* Stretchable ,该列的宽度可以进行拉伸,以时其填满表格中空闲的空间;
* Collapsed,该列将被隐藏;
注:在指定列的时候是根据对应的列号进行指定的,列号从 0 开始;
一个列可以同时拥有拉伸和收缩的属性;
表格布局中,列的宽度由该列中最宽的那个单元决定,整个表格的宽度则取决
于父容器的宽度;
表格布局还支持嵌套,可以将一个表格布局放在另一个表格布局中,也可以在
表格布局中添加其他的界面布局,例如:线性布局、相对布局等;
案例如下:
效果实现,使用线性布局和表格布局嵌套;
效果图如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- 嵌套表格布局 -->
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#DEB887"
android:stretchColumns="2" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="独占一行" />
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button2" />
</TableRow>
</TableLayout>
<!-- 隐藏列,隐藏第二列,拉伸第三列 -->
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00008B"
android:collapseColumns="1"
android:stretchColumns="2" >
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button5" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button6" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button7" />
</TableRow>
</TableLayout>
<!-- 拉伸 2 3 两列 收缩第1列 -->
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#7FFF00"
android:shrinkColumns="0"
android:stretchColumns="1" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="独占一行的按钮" />
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button9" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button10" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button11" />
</TableRow>
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button12" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button13" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button14" />
</TableRow>
</TableLayout>
</LinearLayout>
分享到:
相关推荐
Android移动应用开发表格布局TableLayout的特点.pdf 学习资料 复习资料 教学资源
界面布局之表格布局TableLayout+TableRow(代码).
Android移动应用开发表格布局TableLayout的常用属性.pdf 学习资料 复习资料 教学资源
主要为大家详细介绍了Android布局之表格布局TableLayout,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
表格布局TableLayout以行列的形式管理子元素,每一行是一个TableRow布局对象,当然也可以是普通的View对象,TableRow离每放一个元素就是一列,总列数由列数最多的那一行决定。 我们看一个例子: <?xml version=...
用Android Studio 2.3.3做的表格布局例子,主要用到<TableLayout>、标签,还有android:shrinkColumns="0,1,2"、android:layout_column="0"等设置。
主要为大家详细介绍了Android Studio实现简易计算器,表格布局TableLayout,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
表格布局的标签是TableLayout,TableLayout继承了LinearLayout。所以它依然是一个线性布局。 前言: 1、TableLayout简介 2、TableLayout行列数的确定 3、TableLayout可设置的属性详解 4、一个包含4个TableLayout布局...
主要为大家详细介绍了Android开发之TableLayout表格布局,表格布局模型是以行列的形式管理子控件,对TableLayout表格布局感兴趣的小伙伴们可以参考一下
Tablelayout类以行和列的形式对控件进行管理,每一行为一个TableRow对象,或一个View控件。当为TableRow对象时,可在TableRow下添加子控件,默认情况下,每个子控件占据一列。 当为View时,该View将独占一行
NULL 博文链接:https://sarin.iteye.com/blog/1754910
TableLayout,实现动态添加和删除行,判断行中的数据是否含有空值,可以手动地输入数据,也可以选择数据添加在表格中,并实现统计表格中的数据。
表格布局(TableLayout):按照行列方式布局组件。 相对布局(RelativeLayout):相对其它组件的布局方式。 绝对布局(AbsoluteLayout):按照绝对坐标来布局组件。 1. 线性布局 线性布局是Android开发中最...