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

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. Spring相框

    1.什么是Spring相框?Spring有哪些主要模块框架? Spring框架是一个为Java应用程序的开发提供了综合.广泛的基础性支持的Java平台. Spring帮助开发人员攻克了开发中基础性的问 ...

  2. CheckBox和控件Foreach循环

    .aspx代码例如以下: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Sam ...

  3. 6.组函数(avg(),sum(),max(),min(),count())、多行函数,分组数据(group by,求各部门的平均工资),分组过滤(having和where),sql优化

     1组函数 avg(),sum(),max(),min(),count()案例: selectavg(sal),sum(sal),max(sal),min(sal),count(sal) from ...

  4. adt-bundle-windows-x86_32-20140702

    adt-bundle-windows-x86_32-20140702 Windows > Preference,在Android里没有NDK选项 法一:help->install new ...

  5. Java 并发编程(三)为线程安全类中加入新的原子操作

    Java 类库中包括很多实用的"基础模块"类.通常,我们应该优先选择重用这些现有的类而不是创建新的类.:重用能减少开发工作量.开发风险(由于现有类都已经通过測试)以及维护成本.有时 ...

  6. UNIX网络编程卷1 server程序设计范式7 预先创建线程,以相互排斥锁上锁方式保护accept

    本文为senlie原创.转载请保留此地址:http://blog.csdn.net/zhengsenlie 1.预先创建一个线程池.并让每一个线程各自调用 accept 2.用相互排斥锁代替让每一个线 ...

  7. Javascript语言精粹之String常用方法分析

    Javascript语言精粹之String常用方法分析 1. String常用方法分析 1.1 String.prototype.slice() slice(start,end)方法复制string的 ...

  8. 日历的问题C语言,C++(boost),python,Javascript,Java和Matlab实现

    今天看到一个很有意思的话题,例的标题叙述性描述,下面: 根据以下信息来计算1901年1月1至2000年12月31适逢星期日每个月的第一天的合伙人数量? a)  1900.1.1星期一 b)  1月,3 ...

  9. Ceph更多Mon 更多mds

    1.当前状态 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdWpfbW9zcXVpdG8=/font/5a6L5L2T/fontsize/400/fill ...

  10. Python多线程的threading Event

    Python threading模块提供Event对象用于线程间通信.它提供了一组.拆除.等待用于线程间通信的其他方法. event它是沟通中最简单的一个过程之中,一个线程产生一个信号,号.Pytho ...