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

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. 【iOS】文件下载小记

    下载文件到NSURLConnection与NSURLSession两种,一种有恨悠久的历史了. 使用相对麻烦,后者是新出来的,添加了一些额外的功能. 一.NSURLConnection实现下载 TIP ...

  2. CSS selectors for Selenium with example,selenium IDE

    CSS selectors for Selenium with example http://seleniumeasy.com/selenium-tutorials/css-selectors-tut ...

  3. cocoa动态方法决议及消息转发

    假设给一个对象发送不能响应的消息,同一时候又没有进行动态方法决议,又没实现消息转发,那么就会引发以下的crash信息 2014-07-30 15:47:54.434 MethodNotFind[171 ...

  4. EBS并发管理器请求汇总(按照并发消耗时间,等待时间,平均等待事件等汇总)

    此数据集用于确定正在使用中并发管理器,并可与实际的在启动时分配的并发管理器.而且考虑完成状态为 正常/警告 的请求. select q.concurrent_queue_name, count(*) ...

  5. SVNKIT一段代码的分析

    打印SVNkit版本库中的结构: 函数如下: 调用方法如下: listEntries(repository, ""); System.out.println("XXXXX ...

  6. maven 项目中使用 jstl标签

    在pom.xml文件下面增加如下的依赖包: <dependency> <groupId>javax.servlet</groupId> <artifactId ...

  7. pygame系列_font游戏字体

    在pygame游戏开发中,一个友好的UI中,漂亮的字体是少不了的 今天就给大伙带来有关pygame中字体的一些介绍说明 首先我们得判断一下我们的pygame中有没有font这个模块 1 if not ...

  8. Json,Gson,FastJson解析笔记

    Json,Gson,FastJson解析笔记 1.将JavaBean转换成Json对象: public static String CreatJsonFromObject(Object key,Obj ...

  9. POJ2676 Sudoku [数独]

    好题,也非常有用,犯了几个错误 1.在枚举赋值的时候,思维有个错误:当当前的赋值不能填完这个数独,应该是继续下一个循环,而不是return false 终止枚举 2.Generic Programin ...

  10. Ubuntu下轻松切换GDM, LightDM , KDM

    如果已经安装LightDM和GDM登录显示器.那么在Ubuntu下怎么在各种DM间任意切换呢? 举例: 以切换到GDM为例,打开终端,使用命令: sudo dpkg-reconfigure gdm 接 ...