版本:Android4.3 API18  学习整理:liuxinming

概念

     TableLayout继承了LinearLayout,因此它的本质依然是线性布局管理器。
     表格布局采用行,列的形式来管理UI组件,TableLayout并不需要明确地申明包含多少行,多少列,而是通过添加TableRow,其他组件来控制表格的行数和列数。

单元格设置的三种行为方式

XML属性 相关方法 说明
android:collapseColumns setColumnCollapsed(int,boolean) 设置需要被隐藏的列的序列号。多个用逗号隔开
android:shrinkColumns setShrinkAllColumns(boolena) 设置允许被收缩的列的序列号
android:stretchColumns setStretchAllColumns(boolena) 设置允许被拉伸的列的序列号

说明:TableLayout 继承了LinearLayout,因此它完全可以支持LinearLayout所支持的全部XML属性

下面看UI布局XML代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
> <!-- 定义第一个表格布局,指定第2列允许收缩,第3列允许拉伸 -->
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
android:stretchColumns="2"
>
<!-- 直接添加按钮,它自己会占一行 -->
<Button android:id="@+id/button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="占一行的按钮"
/>
<!-- 添加一行表格 begin -->
<TableRow >
<!-- 为该行添加三个按钮 begin -->
<Button android:id="@+id/button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通按钮"
/>
<Button android:id="@+id/button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="收缩的按钮,收缩的按钮,收缩的按钮"
/>
<Button android:id="@+id/button04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拉伸的按钮"
/>
<!-- 为该行添加三个按钮 end -->
</TableRow>
<!-- 添加一行表格 end --> </TableLayout>
<!-- 定义第二个表格布局,指定第2列被隐藏 -->
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:collapseColumns="1"
>
<!-- 占一行的按钮 -->
<Button android:id="@+id/button011"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="占一行的按钮"
/>
<!-- 添加一行表格并添加三个按钮 begin -->
<TableRow >
<!-- 为该行添加三个按钮 begin -->
<Button android:id="@+id/button12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通按钮"
/>
<Button android:id="@+id/button13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="我是被隐藏掉的按钮"
/>
<Button android:id="@+id/button14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通按钮"
/>
<!-- 为该行添加三个按钮 end -->
</TableRow>
<!-- 添加一行表格并添加三个按钮 end -->
</TableLayout>
<!-- 定义第三个表格布局,指定第2列和第3列可以被拉伸 -->
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1,2"
>
<!-- 占一行的按钮 -->
<Button android:id="@+id/button05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="占一行的按钮"
/>
<!-- 添加一行表格并添加三个按钮 begin -->
<TableRow >
<!-- 为该行添加三个按钮 begin -->
<Button android:id="@+id/button06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通按钮"
/>
<Button android:id="@+id/button07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拉伸的按钮"
/>
<Button android:id="@+id/button08"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拉伸的按钮"
/>
<!-- 为该行添加三个按钮 end -->
</TableRow>
<!-- 添加一行表格并添加三个按钮 end -->
<!-- 再次添加一个表格并添加两个按钮 begin -->
<TableRow >
<Button android:id="@+id/button09"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通的按钮"
/>
<Button android:id="@+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拉伸的按钮"
/>
</TableRow>
<!-- 再次添加一个表格并添加两个按钮 end -->
</TableLayout> </LinearLayout>

讲解:

   上面XML布局页面中定义了三个TableLayout
   1、第一个TableLayout,指定第2列允许收缩,第3列允许拉伸
   2、第二个TableLayout,指定第2列被隐藏(注意看效果图和XML对比)
   3、第三个TableLayout,指定第2列和第3列允许拉伸。
   注:第二个TableLayout表格我们指定了android:collapseColumns="1" ,这意味着第2列中间的按钮将会被隐藏。

调试效果图:




PS:下一节介绍帧布局(FrameLayout),FrameLayout直接继承了ViewGroup组件

欢迎Android , php 同学加群 QQ :224784042 交流
学习的结果,依靠于每天的持之以恒!!不是特忙,特加班情况,会每天更新一篇Android学习笔记,欢迎大家互相交流,学习,共同进步。
偶菜鸟一枚!!!!!!
晚安!


Android开发5:布局管理器2(表格布局TableLayout)的更多相关文章

  1. Android布局管理器(表格布局)

    表格布局有TableLayout所代表,TableLayout继承了LinearLayout,因此他的本质依然是LinearLayout. 表格布局采用行.列的形式来进行管理,在使用的时候不需要声明多 ...

  2. 【Android 应用开发】AndroidUI设计之 布局管理器 - 详细解析布局实现

    写完博客的总结 : 以前没有弄清楚的概念清晰化 父容器与本容器属性 : android_layout...属性是本容器的属性, 定义在这个布局管理器的LayoutParams内部类中, 每个布局管理器 ...

  3. [置顶] Android布局管理器 - 详细解析布局实现

    布局管理器都是以ViewGroup为基类派生出来的; 使用布局管理器可以适配不同手机屏幕的分辨率,尺寸大小; 布局管理器之间的继承关系 : 在上面的UML图中可以看出, 绝对布局 帧布局 网格布局 相 ...

  4. AndroidUI设计之 布局管理器 - 详细解析布局实现

    写完博客的总结 : 以前没有弄清楚的概念清晰化 父容器与本容器属性 : android_layout...属性是本容器的属性, 定义在这个布局管理器的LayoutParams内部类中, 每个布局管理器 ...

  5. android开发4:Android布局管理器1(线性布局,相对布局RelativeLayout-案例)

    控件类概述 View 可视化控件的基类 属性名称 对应方法 描述 android:background setBackgroundResource(int) 设置背景 android:clickabl ...

  6. Android布局管理器(线性布局)

    线性布局有LinearLayout类来代表,Android的线性布局和Swing的Box有点相似(他们都会将容器里面的组件一个接一个的排列起来),LinearLayout中,使用android:ori ...

  7. Android布局管理器(贞布局)

    贞布局有FrameLayout所代表,它直接继承了ViewGroup组建 贞布局为每个加入其中的组件创建一个空白区域(一帧),所以每个子组件占用一帧,这些贞都会根据gravity属性执行自动对齐 贞布 ...

  8. 二、Android应用的界面编程(二)布局管理器

    一.线性布局所有布局都可以作为容器类使用,因此可以调用多个重载的addView()向布局管理器中添加组件.实际上,我们完全可以用一个布局管理器嵌套到其他布局管理器中---因为布局管理器也继承了View ...

  9. Android UI组件:布局管理器

    为了更好的管理Android应用的用户界面中的组件,Android提供了布局管理器.通过使用布局管理器,Android应用的图形用户界面具有良好的平台无关性.通常,推荐使用布局管理器来管理组件的分布. ...

随机推荐

  1. Oracle查看表空间使用情况

     查看表空间使用情况 select upper(f.tablespace_name) "表空间名",        d.tot_grootte_mb "表空间大小(m ...

  2. Materialized View in Oracle - Concepts and Architecture

    List all of MV inoracle: select owner, query, query_len from dba_mviews See content of aMV: select * ...

  3. javascript每日一练(一)——javascript基础

    一.javascript的组成 ECMAScript DOM BOM 二.变量类型 常见类型有:number, string, boolean, undefined, object, function ...

  4. spring mvc 和 jstl

    spring ,jstl 在maven配置文件的配置:<dependency><groupId>org.springframework</groupId><a ...

  5. Genymotion 插件在 Eclipse 和 Android Studio 中点击后无法初始化 Initialize Engine: failed 解决方法

    Genymotion 插件已更新至 1.0.6,目前无法初始化的问题已经解决. ------------------------------------------------------------ ...

  6. sql: 查询,select

    快速查询数据库中拥有那些表项:(类似linux中的ls, ls |grep table_name*)select * from tab where tname like 'YOUR_QERYNAME% ...

  7. jdbcType与javaType的对应关系

    java.sql.Types 值 Java 类型 IBM DB2 Oracle Sybase SQL Informix IBM Content Manager BIGINT java.lang.lon ...

  8. Android下QQ空间查看大图特效

    近期在做一个项目,里面有一个功能是实现Android QQ好友动态里面的缩略图放大,查看大图的效果.用过都知道,这个特效非常赞的,没用过的下载个玩玩吧.我刚開始以为放大的那个大图是一个Activity ...

  9. jsoncpp 不能处理long类型数据

    jsoncpp,是一个c++的解析和生成json的开源工具.假设你的c++程序须要解析或生成json,它会使这个过程变得非常easy! 可是,今天在用jsoncpp进行生成json的时候报了错误,非常 ...

  10. 使用hadoop ecipse插件须要注意的问题

    1.关于run on hadoop的问题: 在未用hadoop eclipse插件前,我以为通过hadoop eclipse 插件不但能够管理hdfs,还能够自己主动打包程序.并帮我自己主动设置Con ...