TableLayout表格布局
2016-03-14 21:58
330 查看
表格布局模型以行列的形式管理子控件,每一行为一个TableRow的对象,当然也可以是一个View的对象。TableRow可以添加子控件,每添加一个为一列。
TableLayout属性:
android:collapseColumns:将TableLayout里面指定的列隐藏,若有多列需要隐藏,请用逗号将需要隐藏的列序号隔开。
android:stretchColumns:设置指定的列为可伸展的列,以填满剩下的多余空白空间,若有多列需要设置为可伸展,请用逗号将需要伸展的列序号隔开。
android:shrinkColumns:设置指定的列为可收缩的列。当可收缩的列太宽(内容过多)不会被挤出屏幕。当需要设置多列为可收缩时,将列序号用逗号隔开。
android:layout_colum:设置该控件在TableRow中指定的列。
android:layout_span:设置该控件所跨越的列数.
具体看实现的代码,代码里面写了注释,可以对照运行结果进行分析
运行截图
TableLayout属性:
android:collapseColumns:将TableLayout里面指定的列隐藏,若有多列需要隐藏,请用逗号将需要隐藏的列序号隔开。
android:stretchColumns:设置指定的列为可伸展的列,以填满剩下的多余空白空间,若有多列需要设置为可伸展,请用逗号将需要伸展的列序号隔开。
android:shrinkColumns:设置指定的列为可收缩的列。当可收缩的列太宽(内容过多)不会被挤出屏幕。当需要设置多列为可收缩时,将列序号用逗号隔开。
android:layout_colum:设置该控件在TableRow中指定的列。
android:layout_span:设置该控件所跨越的列数.
具体看实现的代码,代码里面写了注释,可以对照运行结果进行分析
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="下面是三个TableLayout" /> <!--定义一个表格,2列可以收缩,3列可以拉伸--> <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:shrinkColumns="1" android:stretchColumns="2"> <TableRow> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="正常情况"/> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="收缩了的按钮收缩了的按钮收缩了的按钮"/> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="可以被拉伸可以被拉伸"/> </TableRow> </TableLayout> <!--android:collapseColumns隐藏某列属性--> <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:collapseColumns="2"> <TableRow> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="正常情况"/> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="我被隐藏了"/> <!--根据索引值第三个按钮才是隐藏的--> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="正常"/> </TableRow> </TableLayout> <!--填充剩下的空间--> <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="1"> <TableRow> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="正常情况"/> <Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="我横跨2列"/> </TableRow> </TableLayout> </LinearLayout>
运行截图
相关文章推荐
- Android布局的小窍门?
- Web布局连载——两栏固定布局(五)
- 按右键另存图片只能存BMP
- photoshop去除图片上的水印
- 交换机升级排障实例
- 样式表CSS布局经验
- upload上传单张图片
- 图片引发的溢出危机(图)
- 在winform下实现左右布局多窗口界面的方法之续篇
- C#实现把彩色图片灰度化代码分享
- C#将图片和字节流互相转换并显示到页面上
- C#监控文件夹并自动给图片文件打水印的方法
- css网页布局中注意的几个问题小结
- DL.DT.DD实现左右的布局简单例子第1/2页
- 使用CSS框架布局的缺点和优点小结
- div+CSS网页布局的意义与副作用原因小结第1/2页
- 纯CSS实现的当鼠标移上图片添加阴影效果代码
- 在winform下实现左右布局多窗口界面的方法
- 如何使用C#从word文档中提取图片
- C#实现打开画图的同时载入图片、最大化显示画图窗体的方法