表格布局有TableLayout所代表,TableLayout继承了LinearLayout,因此他的本质依然是LinearLayout。

表格布局采用行、列的形式来进行管理,在使用的时候不需要声明多少行、多少列,而是通过添加TableRow、其他组件来控制表格的行数和列数。

每次向TableLayout添加一个TableRow,该TableRow就是一个表格行,同时TableRow也是容器,可以在其中不断的添加其他的组件,每添加一个子组件,该表格的列就增加一列

在表格布局管理器中,可以为单元格设置如下三种行为方式

  1. Shrinkable:如果某一列被设置为Shrinkable,那么该列的所有单元格的宽度可以被收缩,以保证该表格能适应父容器的宽度
  2. Stretchable:如果某一列被设置为Stretchable,那么该列的所有单元格的宽度可以被拉伸,以保证组件能全部填满表格空余控件
  3. Collapsed:如果某个列被设置为该属性,那么该列的所有单元格都会被隐藏

因为TableLayout继承了LinearLayout类,因此除了支持LinearLayout的全部属性外还支持下面的三个属性

XML属性

方法

说明

android:collapseColumns

setColumnCollapsed(int,boolean)

设置需要被隐藏的列的序号,多个使用都逗号隔开

android:shrinkColumns

setShrinkAllColumns(boolean)

设置允许被收缩的列的序号,多个使用逗号隔开

android:stretchColumns

setStretchAllColumns(boolean)

设置允许被拉伸的列的序号,多个使用逗号隔开

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context="com.example.tablelayout.MainActivity" > <!-- 第一个TableLayout,指定二列允许收缩,三列允许拉伸 -->
<TableLayout
android:id="@+id/tableLayout_one"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
android:stretchColumns="3"> <Button
android:id="@+id/ok1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="独自一行的按钮"/>
<TableRow>
<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> <!-- 第二个TableLayout,指定二列允隐藏-->
<TableLayout
android:id="@+id/tableLayout_two"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:collapseColumns="2"> <Button
android:id="@+id/ok5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="独自一行的按钮"/>
<TableRow>
<Button
android:id="@+id/ok6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通按钮"/>
<Button
android:id="@+id/ok7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="收缩按钮"/>
<Button
android:id="@+id/ok8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="隐藏按钮"/>
</TableRow>
</TableLayout> <!-- 第三个TableLayout,指定二列允许拉伸,三列允许拉伸 -->
<TableLayout
android:id="@+id/tableLayout_three"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1,2"> <Button
android:id="@+id/ok9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="独自一行的按钮"/>
<TableRow>
<Button
android:id="@+id/ok10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通按钮"/>
<Button
android:id="@+id/ok11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拉伸按钮"/>
<Button
android:id="@+id/ok12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拉伸按钮"/>
</TableRow>
</TableLayout>
</LinearLayout>

Android布局管理器(表格布局)的更多相关文章

  1. android的布局管理器

    理论上通过setContentView(view)能够把一个view设置到activity中,但当你有很多个view控件的时候,就需要用android的布局管理器来管理view控件了. android ...

  2. android中常用的布局管理器(二)

    接上篇博客 (3)LinearLayout     线性布局管理器 线性布局管理器是将放入其中的组件按照垂直或水平方向来布局,每一行或每一列只能放一个组件,并且不会换行,当组件排列到窗体的边缘后,后面 ...

  3. 第1组UI组件:布局管理器

    1 布局管理的来源 为了让UI在不同的手机屏幕上都能运行良好----不同手机屏幕的分辨率/尺寸并不完全相同,如果让程序手动控制每个组件的大小.位置,会给编程带来巨大的麻烦.为了解决这个问题.andro ...

  4. 5、Java Swing布局管理器(FlowLayout、BorderLayout、CardLayout、BoxLayout、GirdBagLayout 和 GirdLayout)

    5.Java-Swing常用布局管理器       应用布局管理器都属于相对布局,各组件位置可随界面大小而相应改变,不变的只是其相对位置,布局管理器比较难以控制,一般只在界面大小需要改是才用,但即使这 ...

  5. Java-Swing常用布局管理器

    http://www.cnblogs.com/hthuang/p/3460234.html   5.Java-Swing常用布局管理器       应用布局管理器都属于相对布局,各组件位置可随界面大小 ...

  6. JAVA布局管理器

    JAVA的界面布局原理:由于Java是跨平台语言,使用绝对坐标显然会导致问题,即在不同平台.不同分辨率下的显示效果不一样.Java 为了实现跨平台的特性并且获得动态的布局效果,Java将容器内的全部组 ...

  7. 面试题-Java基础-布局管理器

    1.什么是布局管理器? 布局管理器用来在容器中组织组件.

  8. Qt之布局管理器

    简述 Qt的布局系统提供了一个简单的和强有力的方式,来自动排列窗口子控件布局. 所有QWidget子类可以使用布局来管理他们的子控件.QWidget::setLayout()函数可以为一个控件布局.当 ...

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

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

随机推荐

  1. LeetCode解题报告:LRU Cache

    LRU Cache Design and implement a data structure for Least Recently Used (LRU) cache. It should suppo ...

  2. 使用Git将本地代码上传到GitHub

    #1注册GitHub账号 *1)到https://github.com/注册GitHub账号 #2在GitHub上建立GitHub仓库 *1)登录后点击右下方的"new repository ...

  3. 移动大数据时代最IN编程语言必读书单

    移动大数据时代最IN编程语言必读书单 这是一个快速更迭,快鱼吃慢鱼的时代.从IT 时代演变成 DT 时代,再到现在的智能时代.急速革新的各种新技术.新工具.新平台,需要程序员掌握良好的编程思想和学习方 ...

  4. shell 执行jar 的命令

    #!/bin/sh ############## #判断是否程序已启动 jappname='Test' mainclasspath="com.company.commontest.test& ...

  5. 51单片机的堆栈指针(SP)

    堆栈指针(SP,Stack Pointer),专门用于指出堆栈顶部数据的地址. 那么51单片机的堆栈在什么地方呢?由于单片机中存放数据的区域有限,我们不能够专门分配一块地方做堆栈,所以就在内存(RAM ...

  6. Hibernate(六)一对一双向关联映射

    在上次的博文Hibernate从入门到精通(五)一对一单向关联映射中我们讲解了一下一对一单向关联映射, 这次我们继续讲解一下与之对应的一对一双向关联映射. 一对一双向关联 与一对一单向关联映 射所不同 ...

  7. PHP_SELF、 SCRIPT_NAME、 REQUEST_URI 区别

    $_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在用法上是非常相似的,他们返回的都是与当前正在使用的页面地址有关的 ...

  8. AutoLayout--masonry使用

        [label1 mas_makeConstraints:^(MASConstraintMaker *make) {         //使左边间距为         make.left.equ ...

  9. 324. Wiggle Sort II

    这个题真是做得我想打人了.我生起气来连自己都打. 一开始quick select没啥可说的.但是in place把老命拼了都没想出来.. 看网上的答案是3 partition,MAP式子一看就由衷地反 ...

  10. 初学scala2——case class

    case class,样例类,有人也叫条件类. 例如: case class Person(name:String, age:Int) 好用之处: 1.新建类实例不用new Person(..),直接 ...