表格布局最基本的三个属性:

XML代码实例:

<?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" >
<!-- 定义第一个表格布局,指定第2列同意收缩,第3列同意拉伸 -->
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="match_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:id="@+id/ok1"
android:text="独"
/>
<!-- 加入一个表格行 -->
<TableRow android:layout_width="match_parent" android:layout_height="wrap_content">
<Button android:id="@+id/ok2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="普"/>
<Button android:id="@+id/ok3" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="收"/>
<Button android:id="@+id/ok4" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="拉"/>
</TableRow>
</TableLayout> <!-- 定义第二个表格布局,指定第2列隐藏 -->
<TableLayout android:id="@+id/TableLayout02" android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:collapseColumns="1"
>
<!-- 直接加入button,它自己会占一行 -->
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="独"
/>
<TableRow android:layout_width="match_parent" android:layout_height="wrap_content">
<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列和第三列同意被拉伸 -->
<TableLayout android:id="@+id/TableLayout03"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1,2" android:layout_marginTop="30dp"
>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="独"
/>
<TableRow android:layout_width="match_parent" android:layout_height="wrap_content">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="普通button"/>
<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 android:layout_width="match_parent" android:layout_height="wrap_content">
<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>

效果:

总结:

假设没实用tableRow,直接用组件,将自己独占一行,而且填充父窗体

而假设用tableRow,上下两行各列将对齐。

Android中的表格布局TableLayout的更多相关文章

  1. .Net程序猿玩转Android开发---(8)表格布局TableLayout

    表格布局TableLayout是Android中比較经常使用的一个布局控件,既然是表格,肯定有行和列,TableLayout中的行有TableRow组成.列依据每行控件的数量来确定 假如第一行有3个控 ...

  2. Android 自学之表格布局 TableLayout

    表格布局(TableLayout),表格布局采用行.列的形式来管理UI组件,TableLayout并不需要明确的声明多少行,多少列,而是通过TableRow.其他组件来控制表格的行数和列数. 每次想T ...

  3. Android中常用的布局

    一般分为5大类. Android中所有的空间第一字母都是大写 1.线性布局 LinearLayout 2.相对布局 RelativeLayout 3.帧布局--分层显示  FrameLayout 4. ...

  4. Android 中常用的布局

    一.线性布局----LinearLayout   horizontal 水平 <?xml version="1.0" encoding="utf-8"?& ...

  5. Android中的五大布局

    Android中的五大布局 1.了解布局 一个丰富的界面总是要由很多个控件组成的,那我们如何才能让各个控件都有条不紊地 摆放在界面上,而不是乱糟糟的呢?这就需要借助布局来实现了.布局是一种可用于放置很 ...

  6. android中的常用布局管理器(三)

    接上篇博客 (5)TableLayout     表格布局管理器 在android中,线性布局和表格布局用的是最多的. 在很多的输出操作中,往往会使用表格的形式对显示的数据进行排版,tablelayo ...

  7. Android中的LinearLayout布局

    LinearLayout : 线性布局 在一般情况下,当有很多控件需要在一个界面列出来时,我们就可以使用线性布局(LinearLayout)了,  线性布局是按照垂直方向(vertical)或水平方向 ...

  8. Android 表格布局<TableLayout>

    表格布局即,tableLayout,表格布局通过行.列的形式来管理UI组件,TablelLayout并不需要明确地声明包含多少行.多少列,而是通过TableRow,以及其他组件来控制表格的行数和列数, ...

  9. Android开发5:布局管理器2(表格布局TableLayout)

    版本:Android4.3 API18  学习整理:liuxinming 概念      TableLayout继承了LinearLayout,因此它的本质依然是线性布局管理器.      表格布局采 ...

随机推荐

  1. android 防止多次点击,它会导致事件侦听响应于其他接口

    这里有情况: A当点击跳转至B介面,点击B接口结束后,到A界面中 1.此时在B界面中,设置点击事件,点击后结束B v.setOnClickListener(new OnClickListener() ...

  2. 50 tips of JavaScript

    50 tips of JavaScript,这些坑你都知道吗? 1.在局部作用域中,使用var操作符定义的变量将成为定义该变量的作用域中的局部变量,省略var的会创建全局变量:在全局作用域中,不管是否 ...

  3. 李林APUE之进程的封装

    1.子进程是父进程的副本,获得父进程的数据空间/堆/栈,父子进程共享代码段.子进程从fork后開始运行.返回值=0表示子进程,由于子进程能够通过函数来获取父进程的ID,可是父进程无法知道子进程的ID. ...

  4. Nagios+pnp4nagios+rrdtool 安装配置为nagios添加自定义插件(三)

    nagios博大精深,可以以shell.perl等语句为nagios写插件,来满足自己监控的需要.本文写mysql中tps.qps的插件,并把收集到的结果以图形形式展现出来,这样输出的结果就有一定的要 ...

  5. String,StringBuffer以及StringBuilder的差别

    1.定义: String:String 类代表字符串. Java 程序中的全部字符串字面值(如"abc" )都作为此类的实例实现. 字符串是常量:它们的值在创建之后不能更改. 字符 ...

  6. 在iOS7中改动状态栏字体的颜色

    状态栏的字体为黑色:UIStatusBarStyleDefault 状态栏的字体为白色:UIStatusBarStyleLightContent 一.在info.plist中,将View contro ...

  7. centos 安装 使用本地图像文件来安装网络安装

    有时很无奈,无盘,U它只有盘4G而一个centos该盘4.16G,如何将它安装了网络安装,对不起,你想用20M更多的带宽,并注意使用网络启动盘的方法 没有条件,应该创造条件: 网络安装,需要下载图片, ...

  8. ftk学习记(消息框篇)

    [ 声明:版权全部,欢迎转载,请勿用于商业用途.  联系信箱:feixiaoxing @163.com] 上一篇说到了输入框.闲话不多说,首先看结果显示, 大家看看效果是不是和我们之前说的一样.今天, ...

  9. 怎么样MyEclipse配置Tomcat?

    1.下载tomcat免安装版.tomcat路径不包含空格 http://download.csdn.net/detail/u014112584/7549191 2.windows -preferenc ...

  10. IOS私人API用法

    先要使用class-dump 和dumpFrameworks.pl 工具 将ios的framework导出来. 下面是工具的下载地址: class-dump下载地址http://www.codethe ...