-
Android 表格布局
2018-05-08 20:19:30很好用,没限制,可以找到一些关于表格布局的信息和使用注意点。 -
android表格布局
2013-11-13 00:39:20TableLayout继承了LinearLayout,他的本质依然是线性布局管理器 TableLayout并不需要明确地生命包含多少行、多少列,而是通过TableRow、其他组件来控制表格的行数和列数 ...在android表格布局TableLayout继承了LinearLayout,他的本质依然是线性布局管理器
TableLayout并不需要明确地生命包含多少行、多少列,而是通过TableRow、其他组件来控制表格的行数和列数
每次向TableLayout中添加一个TableRow,该TableRow就是一个表格行,TableRow也是容器,每往其中添加一个子组件就是增加一列
在android表格布局管理器中,可以为单元格设置如下三种行为方式:
Shrinkable:如果某个列被设置为此,那么该列的所有单元格的宽度可以被收缩,以保证该表格能适应父容器的宽度
Stretchable:如果某个列被设置为此,那么该列的所有单元格的宽度可以被拉伸,以保证组件能完全填满表格剩余空间
Collapsed:如果某个列被设为此,那么该列的所有单元格将被隐藏。
值得一提的是:android中,列是从0开始的。
以下例子中
第一个TableLayout,指定第2列允许收缩,第3列允许拉伸
第二个TableLayout,指定第2列被隐藏
第三个TableLayout,指定第2列和第3列允许拉伸
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <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/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 android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:collapseColumns="1"> <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 android:id="@id/TableLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="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表格布局
2021-01-27 11:29:411、TableLayout表格布局 表格布局就是让控件以表格的形式来排列组件的,只要将组件或信息放在单元格中,控件就可以整齐的排列。 在TableLayout中,行数由TableRow对象控制的,即布局中由多少TableRow对象,就由...1、TableLayout表格布局
-
表格布局就是让控件以表格的形式来排列组件的,只要将组件或信息放在单元格中,控件就可以整齐的排列。
-
在TableLayout中,行数由TableRow对象控制的,即布局中由多少TableRow对象,就由多少行。
-
如果我们直接往TableLayout中添加组件的话,那么这个组件将占满一行!!!
-
如果我们想一行上有多个组件的话,就要添加一个TableRow的容器,把组件都丢到里面!
-
Tablerow中的组件个数就决定了该行有多少列,而列的宽度由该列中最宽的单元格决定。
-
Tablerow的Table_width属性,默认是fill_parent的,我们自己设置成其他的值也不会生效!但是layout_height默认是wrapten——content的,我们却可以自己设置大小!
-
整个表格布局的宽度取决于父容器的宽度(占满父容器本身)
-
有多少行就要自己数了,一个Tablerow一行,一个单独组件也一行!多少列则是看Tablerow中的组件个数,组件最多的就是TableLayout的列数。
2、三个常用属性 -
android:collapseColumns:设置需要被隐藏的列的序号
-
android:shrinkColumns:设置允许被收缩的列的列序号
-
android:stretchColumns:设置允许被拉伸的列的列序号
以上这三个属性的列号都是从0开始算的,比如shrinkColunmns=“2”,对应的是第三列!可以设置多个,用逗号隔开比如“0,2”,如果是所有列都生效,则用"*"即可。
除了这三个常用的属性,还有两个属性,分别就是跳格子以及合并单元格,这和HTML中的Table类似: -
android:layout_column=“2”:表示的就是跳过第二个,直接显示到第三个格子处,从一开始算的!
-
android:layout_span=“4”:表示合并4个单元格,也就是说这个组件占4个单元格。
-
-
android表格布局tablelayout的使用场合及简要介绍.pptx
2020-06-08 00:34:31北京信息职业技术学院 | 范美英 Android表格布局TableLayout的使用场合及简要介绍 表格布局TableLayout 一种常用的界面布局它将屏幕划分网格通过指定行和列可以将界面元素添加的网格中 网格的边界对用户是不可见的 ... -
Android 表格布局实例应用
2014-06-06 16:22:17Android 表格布局实例应用 直接把源码下载下来运行即可看到实际效果。 -
Android 表格布局TableLayout示例详解
2021-01-20 10:16:24一、表格布局 TableLayout 表格布局TableLayout以行列的形式管理子元素,每一行是一个TableRow布局对象,当然也可以是普通的View对象,TableRow离每放一个元素就是一列,总列数由列数最多的那一行决定。 我们看一... -
Android表格布局(Table Layout)
2014-11-01 11:01:57Android表格布局(Table Layout) 先来看布局管理器之间继承关系图: 图1 可知TableLayout继承了LinearLayout,所以表格布局本质上依然是线性管理器。 表格布局采用行、列的形式来管理组件,它并不需要...Android表格布局(Table Layout)
先来看布局管理器之间继承关系图:
图1
可知TableLayout继承了LinearLayout,所以表格布局本质上依然是线性管理器。
表格布局采用行、列的形式来管理组件,它并不需要明确地声明包含了多少行、多少列,而是通过添加TableRow、其他组件来控制表格的行数和列数。
每向TableLayout添加一个TableRow,该TableRow就是一个表格行,TableRow也是容器,因此它也可以不断地添加组件,每添加一个子组件该表格就添加一列。
TableLayout一般以下面两种方式实现:
(1) 自己作为最顶层父容器
<!--定义一个TableLayout,有两行 第1列所有单元格的宽度可以被收缩,以保证该表格能适应父容器的宽度 第2列所有单元格的宽度可以拉伸,以保证能完全填满表格空余空间--> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/TableLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:shrinkColumns="1" android:stretchColumns="2"> <!--这是此TableLayout的第1行,没有使用TableRow,直接添加一个Button,那么次Button自己占用整行 --> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="独自一行的按钮1"/> <!-- 这是第2行,先添加一个TableRow,并为TableRow添加三个Button,也就是此行包含三列 --> <TableRow> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="普通按钮1"/> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="被收缩的按钮1"/> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="被拉伸的按钮1"/> </TableRow> <!--这是此TableLayout的第3行,没有使用TableRow,直接添加一个Button,那么次Button自己占用整行 --> <Button android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="独自一行的按钮2"/> <!-- 这是第4行,先添加一个TableRow,并为TableRow添加三个Button,也就是此行包含三列 --> <TableRow> <Button android:id="@+id/button6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="普通按钮2"/> <Button android:id="@+id/button7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="被收缩的按钮2"/> <Button android:id="@+id/button8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="被拉伸的按钮2"/> </TableRow> </TableLayout>
效果如下:
图2
这里只有一个TableLayout,如果我们想单独控制地4行,比如想把“普通按钮2”隐藏,也就是增加android:collapseColumns="0",这样会把“普通按钮1”,这一列也隐藏了,如下图:
图3
但如果要实现只“普通按钮2”这列,我们来看下面的实现
(2) LinearLayout作为TableLayout的容器
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">--> <!--定义第1个TableLayout,有两行 第1列所有单元格的宽度可以被收缩,以保证该表格能适应父容器的宽度 第2列所有单元格的宽度可以拉伸,以保证能完全填满表格空余空间--> <TableLayout android:id="@+id/TableLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:shrinkColumns="1" android:stretchColumns="2"> <!--这是此TableLayout的第1行,没有使用TableRow,直接添加一个Button,那么次Button自己占用整行 --> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="独自一行的按钮1"/> <!-- 这是第2行,先添加一个TableRow,并为TableRow添加三个Button,也就是此行包含三列 --> <TableRow> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="普通按钮1"/> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="被收缩的按钮1"/> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="被拉伸的按钮1"/> </TableRow> </TableLayout> <!--定义第2个TableLayout,有两行 第1列所有单元格的宽度可以被收缩,以保证该表格能适应父容器的宽度 第2列所有单元格的宽度可以拉伸,以保证能完全填满表格空余空间--> <TableLayout android:id="@+id/TableLayout2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:collapseColumns="0" android:shrinkColumns="1" android:stretchColumns="2"> <!--这是此TableLayout的第3行,没有使用TableRow,直接添加一个Button,那么次Button自己占用整行 --> <Button android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="独自一行的按钮2"/> <!-- 这是第4行,先添加一个TableRow,并为TableRow添加三个Button,也就是此行包含三列 --> <TableRow> <Button android:id="@+id/button6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="普通按钮2"/> <Button android:id="@+id/button7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="被收缩的按钮2"/> <Button android:id="@+id/button8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="被拉伸的按钮2"/> </TableRow> </TableLayout> </LinearLayout>
效果如下:
图4
通过在第2个TableLayout中增加android:collapseColumns="0"实现,这里需要主要的是LinearLayout的android:orientation属性值的设置,如果没有这一项或是其值为horizontal,那么后面两行都看不到,因为是以水平方向排列的,后面两行显示在前两行的右边,看不到。
-
relativelayout设置边框_Android表格布局之设置边框
2021-01-13 19:17:04Android表格布局本身没有边框,不过可以通过背景色的设置可以实现表格边框的显示。首先可以设置TableRow的背景色,然后设置内容的背景色。根据它们的颜色差就出现了边框。只要微调Content与TableRow的margin和pading...Android表格布局本身没有边框,不过可以通过背景色的设置可以实现表格边框的显示。
首先可以设置TableRow的背景色,然后设置内容的背景色。根据它们的颜色差就出现了边框。只要微调Content与TableRow的margin和pading属性就可以了!
调的过程真是烦人!下次不做这种工作了~呜呜!难受!
贴上布局代码:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white" >
android:id="@+id/table1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:padding="6.5dip" >
android:background="@color/jiemianbiankuang"
android:orientation="horizontal"
android:paddingLeft="0.5dip"
android:paddingRight="0.5dip"
android:paddingTop="1dip" >
android:id="@+id/imageViewMSG"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="0.5dip"
android:layout_marginLeft="0.5dip"
android:background="@color/white"
android:contentDescription="@string/messagecenter"
android:src="@drawable/msg" />
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="0.5dip"
android:layout_marginLeft="0.5dip"
android:background="@color/white"
android:src="@drawable/book" />
android:id="@+id/imageView2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="0.5dip"
android:layout_marginLeft="0.5dip"
android:background="@color/white"
android:src="@drawable/maozi" />
android:background="@color/jiemianbiankuang"
android:orientation="horizontal"
android:paddingLeft="0.5dip"
android:paddingRight="0.5dip"
android:paddingTop="0dip" >
android:id="@+id/imageView4"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="0.5dip"
android:layout_marginLeft="0.5dip"
android:background="@color/white"
android:src="@drawable/earth" />
android:id="@+id/imageView5"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="0.5dip"
android:layout_marginLeft="0.5dip"
android:background="@color/white"
android:src="@drawable/unno" />
android:id="@+id/imageView6"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="0.5dip"
android:layout_marginLeft="0.5dip"
android:background="@color/white"
android:src="@drawable/zuoye" />
界面效果图
Android表格布局(Table Layout)
Android表格布局(Table Layout) 先来看布局管理器之间继承关系图: 图1 可知TableLayout继承了LinearLayout,所以表格布局本质上依然是线性管理器. 表格布局采用 ...
Android 表格布局<;TableLayout>;
表格布局即,tableLayout,表格布局通过行.列的形式来管理UI组件,TablelLayout并不需要明确地声明包含多少行.多少列,而是通过TableRow,以及其他组件来控制表格的行数和列数, ...
[android] 表格布局和绝对布局
/*****************2016年4月28日 更新*************************************/ 知乎:为什么Android没有像iOS一样提供autolay ...
Android 表格布局 TableLayout
属性介绍 stretchColumns:列被拉伸 shrinkColumns:列被收缩 collapseColumns:列被隐藏 举例测试
android横屏布局文件设置
一.AndroidManifest.xml配置 1.在AndroidManifest.xml的activity(需要禁止转向的activity)配置中加入 android:screenOrient ...
android动态设置边框颜色
-
Android 表格布局 | 学习笔记
2020-08-23 20:43:41表格布局一、表格布局基本知识二、示例演示1. 分步 一、表格布局基本知识 表格布局采用行、列的形式来管理UI组件(用户界面的控件),通过添加TableRow、其他组件来控制表格的行数和列数。 在XML布局文件中定义表格... -
Android 表格布局的RadioButton
2015-10-26 11:34:26通过RadioButton与GridView,实现了单选按钮成表格布局,同时具备单选效果的功能。实现效果见http://blog.csdn.net/ddxxll2008/article/details/49421129 -
Android 表格布局TableLayout
2020-12-06 14:19:21TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:collapseColumns="0" xmlns:android="http://schemas.android.com/apk/res/android"> <Button and. -
Android表格布局之设置边框
2014-07-29 20:41:00Android表格布局本身没有边框,不过可以通过背景色的设置可以实现表格边框的显示。 首先可以设置TableRow的背景色,然后设置内容的背景色。根据它们的颜色差就出现了边框。只要微调Content与TableRow的margin和... -
Android 表格布局、网格布局、帧布局、绝对布局
2021-03-06 17:15:471、表格布局(TableLayout) 表格布局就是让控件以表格的形式来排列组件的,只要将组件或信息放在单元格中,控件就可以整齐的排列。在TableLayout中,行数由TableRow对象控制的,即布局中有多少TableRow对象,就有... -
Android表格布局示例
2016-07-04 20:49:20表格布局以行、列表格的方式布局子组件。TableLayout中使用TableRow来定义多行。