转载自:http://apps.hi.baidu.com/share/detail/33176011
从字面上来看,TableLayout也比较简单,关键是要对相关的属性要熟悉,先看一个简单的例子(后面为效果图):
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0,1,2"
android:shrinkColumns="1,2"
>
<TextView
android:text="Table Test"
android:gravity="center"/>
<TableRow>
<TextView
android:layout_column="1"
android:text="姓名"
android:gravity="center"/>
<TextView
android:text="基本信息"
android:gravity="center"/>
</TableRow>
<TableRow>
<TextView
android:text=" 1 "
android:gravity="center"/>
<TextView
android:text="hoyah"
android:gravity="left"/>
<TextView
android:text="Wuhan University"
android:gravity="right"/>
</TableRow>
<TableRow>
<TextView
android:text=" 2 "
android:gravity="center"/>
<TextView
android:text="Google"
android:gravity="left"/>
<TextView
android:text="hello Google"
android:gravity="right"/>
</TableRow>
<TableRow>
<TextView
android:text="3"
android:gravity="center"/>
<TextView
android:text="Android"
android:gravity="left"/>
<TextView
android:text="Android OS"
android:gravity="right"/>
</TableRow>
</TableLayout>
布局讲解:
android:collapse="1
隐藏该TableLayout里的TableRow的列1,即第2列(从0开始计算),若有多列要隐藏,用“,”隔开。
android:stretchColumns="0,1,2"
设置列0、1、2为可伸展列。
android:shrinkColumns="1,2"
设置列1、2为可收缩列。
android:background="@drawable/picture_name"
本例中没有涉及此属性,它是要设置当前view 的背景图片,图片文件应该放在res文件夹下。
接着我们再看看android官方文档中给出的例子:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:layout_column="1"
android:text="Open..."
android:padding="3dip"
/>
<TextView
android:text="Ctrl-O"
android:gravity="right"
android:padding="3dip"
/>
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:text="Save..."
android:padding="3dip"
/>
<TextView
android:text="Ctrl-S"
android:gravity="right"
android:padding="3dip"
/>
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:text="Save As..."
android:padding="3dip"
/>
<TextView
android:text="Ctrl-Shift-S"
android:gravity="right"
android:padding="3dip"
/>
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF909090"
/>
<TableRow>
<TextView
android:text="X"
android:padding="3dip"
/>
<TextView
android:text="Import..."
android:padding="3dip"
/>
</TableRow>
<TableRow>
<TextView
android:text="X"
android:padding="3dip"
/>
<TextView
android:text="Export..."
android:padding="3dip"
/>
<TextView
android:text="Ctrl-E"
android:gravity="right"
android:padding="3dip"
/>
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF909090"
/>
<TableRow>
<TextView
android:layout_column="1"
android:text="Quit"
android:padding="3dip"
/>
</TableRow>
</TableLayout>
效果图如下,大家可以上机调试一下:
来自:
http://hi.baidu.com/hoyah/blog/item/d9db34275d6f361a8b82a171.html
分享到:
相关推荐
Tablelayout类以行和列的形式对控件进行管理,每一行为一个TableRow对象,或一个View控件。当为TableRow对象时,可在TableRow下添加子控件,默认情况下,每个子控件占据一列。 当为View时,该View将独占一行
主要为大家详细介绍了Android开发之TableLayout表格布局,表格布局模型是以行列的形式管理子控件,对TableLayout表格布局感兴趣的小伙伴们可以参考一下
Android移动应用开发表格布局TableLayout的特点.pdf 学习资料 复习资料 教学资源
用Android Studio 2.3.3做的表格布局例子,主要用到<TableLayout>、标签,还有android:shrinkColumns="0,1,2"、android:layout_column="0"等设置。
TableLayout表格布局模型以行列的形式管理子控件,每一行为一个TableRow的对象, 当然也可以使一个View的对象 2.TableLayout的属性(全局属性) android:collapseColumns=”1,2” 隐藏从0开始的索引列,列之间...
Android移动应用开发表格布局TableLayout的常用属性.pdf 学习资料 复习资料 教学资源
表格布局的标签是TableLayout,TableLayout继承了LinearLayout。所以它依然是一个线性布局。 前言: 1、TableLayout简介 2、TableLayout行列数的确定 3、TableLayout可设置的属性详解 4、一个包含4个TableLayout布局...
界面布局之表格布局TableLayout+TableRow(代码).
本文主要介绍Android TableLayout布局,这里整理了TableLayout的资料,并附示例代码和实现效果图,有兴趣的小伙伴可以参考下
TableLayout 表格布局 采用 行, 列 形式管理子组件,添加TableRow 和 组件 就可以控制表格的行数和列数 GridLayout 网格布局 设置行列来装填控件 AbsoluteLayout 绝对布局 组件位置通过x, y坐标来控制, 布局容器不再...
TableLayout,实现动态添加和删除行,判断行中的数据是否含有空值,可以手动地输入数据,也可以选择数据添加在表格中,并实现统计表格中的数据。
android固定头部和左侧表格实现,可以实现纵向合并,不含TableLayout等布局,简单易懂
NULL 博文链接:https://sarin.iteye.com/blog/1754910
TableLayout跟TableLayout 是一组搭配使用的布局,TableLayout置底,TableRow在TableLayout的上面,而Button、TextView等控件就在TableRow之上,另外,TableLayout之上也可以单独放控件。TableLayout是一个使用复杂的...