Android-TableLayout布局
来源:互联网 发布:照片加相框软件 编辑:程序博客网 时间:2024/05/17 06:54
TableLayout,表格布局采用行列形式管理UI组件,TableLayout不需要明确地声明有多少行和列,而是通过添加TableRow、其它组件来控制表格的行数、列数。
v每次向TableLayout添加一个TableRow,就是在向表格添加一行,TableRow也是容器,可以向TableRow中添加组件,每添加一个组件,即是添加一列。
v如果直接向TableLayout添加组件,则认为这个组件占用一行。
v表格布局中列的宽度即是每一列中最宽的组件的宽度。
v表格布局中,可以为单元格设置如下三种属性:
™
XML属性
相关方法
说明
android:collapseColumns
setColumnCollapsed(int,boolean)
设置需要隐藏的列的序号,多个之间用逗号分隔
Android:shrinkColumns
setShrinkAllColumns(boolean)
设置允许被收缩的列的序号,多个之间用逗号分隔
Android:stretchColumns
setStretchAllColumns(boolean)
设置允许被拉伸的列的序号,多个之间用逗号分隔
xml布局文件:
- <?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"
- >
- <!-- 定义第一个表格布局,指定第2列允许收缩,第3列允许拉伸 -->
- <TableLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:shrinkColumns="1"
- android:stretchColumns="2"
- >
- <!-- 直接添加按钮,它自己会占一行 -->
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="独自一行的按钮"
- />
- <!-- 添加一个表格行 -->
- <TableRow>
- <!-- 为该表格行添加3个按钮 -->
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="普通按钮"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="允许被收缩的按钮"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="允许被拉伸的按钮"
- />
- </TableRow>
- </TableLayout>
- <!-- 定义第二个表格布局 ,指定第二列隐藏-->
- <TableLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:collapseColumns="1"
- >
- <!-- 直接添加按钮,它自己会占一行 -->
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text=" 独自一行的按钮 "
- />
- <!--定义一个表格行-->
- <TableRow>
- <!-- 为该表格行添加3个按钮 -->
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="普通按钮"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="被隐藏的按钮"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="普通按钮 "
- />
- </TableRow>
- </TableLayout>
- <!-- 定义第三个表格布局 ,指定第2、3两列可以被拉伸-->
- <TableLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:stretchColumns="1,2"
- >
- <!-- 直接添加按钮,它自己会占一行 -->
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="独自一行的按钮"
- />
- <!--定义一个表格行-->
- <TableRow>
- <!-- 为该表格行添加3个按钮 -->
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="普通按钮"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="允许被拉伸的按钮"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="允许被拉伸的按钮"
- />
- </TableRow>
- <!--定义一个表格行-->
- <TableRow>
- <!-- 为该表格行添加2个按钮 -->
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="普通按钮"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="允许被拉伸的按钮"
- />
- </TableRow>
- </TableLayout>
- </LinearLayout>
效果图:
- Android布局之TableLayout
- android-TableLayout 表格布局
- tablelayout-android布局
- 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布局
- 解析static 关键字
- js事件大全
- 弹窗插件
- 2012年8月21日
- 简单存储过程分页
- Android-TableLayout布局
- newInstance()方法 JAVA
- JSP SELECT 下拉框 默认值选择数据库查出来的值
- 無線區域網路產出的定義和改進
- python mysql
- ZOJ 3624 Count Path Pair(组合计数)
- jquery radio取值,checkbox取值,select取值,radio选中
- 使用LINQ来简化编程的7个技巧
- 更换头像 鼠标移动显示更改和删除 头像