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

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. 自动更改IP地址反爬虫封锁,支持多线程(转)

    8年多爬虫经验的人告诉你,国内ADSL是王道,多申请些线路,分布在多个不同的电信机房,能跨省跨市更好,我这里写好的断线重拨组件,你可以直接使用. ADSL拨号上网使用动态IP地址,每一次拨号得到的IP ...

  2. ACM-简单题之Least Common Multiple——hdu1019

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  3. win7系统u盘安装过程

    1.准备好带有启动项的U盘,并把镜像解压到里面去 2.插上u盘,开机长按del键进入bois设置界面 在boot页面 1.boot device priority->1st boot devic ...

  4. Python重写C语言程序100例--Part6

    ''' [程序41] 题目:学习static定义静态变量的使用方法 1.程序分析: 2.程序源码: ''' # python没有这个功能了,仅仅能这样了:) def varfunc(): var = ...

  5. Codeforces Jzzhu and Sequences(圆形截面)

    # include <stdio.h> int f[10]; int main() { int x,y,n,j; while(~scanf("%d%d%d",& ...

  6. 促销R语言应用性能

    1.       绩效评估 时间的确定 R测量时间是在最简单的方式提供是system.time性能. system.time(expr, gcFirst=TRUE) 这个函数会在不减少程序执行性能的情 ...

  7. 两种Data Table参数化设置的区别

    首先介绍Data Table的语法: 1.DataTable.value(ParameterID, SheetID) 2.DataTable(ParameterID, SheetID) 以上2种方法的 ...

  8. 它们的定义AlertDialog(二)

    先来看主页面布局 main_activity.xml里面仅仅有一个button(加入点击事件.弹出载入框) 再看MainActivity package com.example.loadingdial ...

  9. Windows Phone开发(6):处理屏幕方向的改变

    原文:Windows Phone开发(6):处理屏幕方向的改变 俺们都知道,智能手机可以通过旋转手机来改变屏幕的显示方向,更多的时候,对于屏幕方向的改变,我们要做出相应的处理,例如,当手机屏幕方向从纵 ...

  10. Qt 3D研究(九):尝试第二边缘检测方法

    Qt 3D研究(九):尝试第二边缘检测方法 三维应用程序,通过FBO.将3D图像渲染成纹理,然后对渲染成的纹理进行图像处理,终于显示在屏幕上的.是风格化后的图案.上一次我使用了一种普通的图像处理方法: ...