Android 表格布局<TableLayout>
来源:互联网 发布:淘宝网点击旺旺没反应 编辑:程序博客网 时间:2024/04/29 11:14
表格布局即,tableLayout,表格布局通过行、列的形式来管理UI组件,TablelLayout并不需要明确地声明包含多少行、多少列,而是通过TableRow,以及其他组件来控制表格的行数和列数,
TableRow也是容器,因此可以向TableRow里面添加其他组件,没添加一个组件该表格就增加一列。
如果想TableLayout里面添加组件,那么该组件就直接占用一行。
在表格布局中,列的宽度由该列中最宽的单元格决定,整个表格布局的宽度取决于父容器的宽度(默认是占满父容器本身)。
TableLayout继承了LinearLayout,因此他完全可以支持LinearLayout所支持的全部XML属性,除此之外TableLayout还支持以下属性:
XML属性 相关用法 说明
1. andriod:collapseColumns setColumnsCollapsed(int ,boolean) 设置需要隐藏的列的序列号,多个用逗号隔开
2.android:shrinkColumns setShrinkAllColumns(boolean) 设置被收缩的列的序列号,多个用逗号隔开
3.android:stretchColimns setSretchAllColumnds(boolean) 设置允许被拉伸的列的序列号,多个用逗号隔开
代码如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- 定义第一个表格布局,指定第二列允许收缩,第三列允许拉伸 -->
<TableLayout
android:id="@+id/tablelayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
android:stretchColumns="2"
>
<!-- 直接添加一个button,他自己会占用一行 -->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="独自占用一行的按钮"/>
<!-- 先添加一个tableRow,在添加三个button, 结果应该是三个button在这个tableRow(行)里面,即排列为一行 -->
<TableRow >
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RBtn1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RBtn2"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RBtn3"/>
</TableRow>
</TableLayout>
</LinearLayout>
上面代码展示了,在tableLayour中使用TableRow的效果,和不使用TableRow的效果,并第二列允许收缩,第三列允许拉伸。运行结果如下所示:
下面说明XML属性的隐藏使用方法,在TableLayout中添加一下代码,
android:collapseColumns="0"
代码如下所示:
注意:属性中设置列号的时候是从0,1,2,3 ....
不是1,2,3...
- android-TableLayout 表格布局
- Android 表格布局<TableLayout>
- android:TableLayout表格布局
- android:TableLayout表格布局
- Android TableLayout表格布局
- Android TableLayout 表格布局
- android:TableLayout表格布局详解
- android:TableLayout表格布局详解
- android:TableLayout表格布局详解
- android:TableLayout表格布局详解
- android:TableLayout表格布局详解
- android:TableLayout表格布局详解
- Android表格布局管理器TableLayout
- android:TableLayout表格布局详解
- Android TableLayout表格布局详解
- android:TableLayout表格布局详解
- android:TableLayout表格布局详解
- android:TableLayout表格布局详解
- ora-01157 处理过程
- 与一名上海学生深度交流上大学的事
- 安装fedora13后我必须要干的几件事
- c语言中结构体内存对齐细致讨论
- __asm__ __volatile__("": : :"memory")含义
- Android 表格布局<TableLayout>
- SQL Server 2008-建立分区表(Table Partition)
- 内存使用(free和vmstat)
- 给每个对程序员敢兴趣的初学者自学网址
- [4750G] Ubuntu硬件优化篇——引导修复双显卡及屏幕亮度调节设置 bumblebee
- 【笔者支招:全方面更改各类特征码——xiame.com】
- 认识Fedora下repo文件
- SAp 语言翻译大师系列4- 界面文本的翻译
- linux 软连接 硬连接