这三个布局就放在一起来写了他们用的比较少,不过为了写这遍
博客我换特意去复习了下,
第一个表格布局TableLayout
表格布局顾名思义 就是与表格类似,以行,列形式来管理其中的组件的,
它是<TableLayout> 标记定义里面必须有一个<TableRow> 作用是占用一行
语法:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
属性列表>
<TableRow 属性列表>
组件
</TableRow>
</TableLayout>
几个特有的属性
android:collapseColumns 需要设置被隐藏的列的序列号
android:shrinkColumns 被收缩的列的序列号
android:stretchColumns 被拉伸的列的序列号
下面写一段代码:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TableRow android:background="#ff3366" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#ff3366" android:text="用户名:"/> </TableRow> <TableRow android:background="#00ff00" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码:"/> </TableRow> </TableLayout>效果图:
这里我设置了2中不同的背景颜色大家看到了吗,知道我想说什么吗
这里就提醒一下,
在TableLayout中每一个TableRow代表一行,
TableRow的宽和高
<TableRow android:background="#00ff00" android:layout_width="wrap_content" android:layout_height="wrap_content">
是固定的无论怎么设置都不会改变,不知道大家是否在意过这一点,也就是做
你不要宽和高也是一样的,看下面的代码我随意改了下
再看下效果图
怎么样,没有收到什么影响吧。
表格布局就说这么多吧
二 帧布局 FrameLayout
在帧布局中 每增加一个组件 将会创建一个空白的区域,
默认情况下帧布局从屏幕的左上角(0,0)坐标点开始布局,多个组件层叠排列,
后面的组件覆盖前面的组件,
语法:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
属性列表>
</FrameLayout>
其特有的属性
android:foreground 帧布局容器的前景图像
android:foregroundGravity 前景图像显示的位置
资料中显示帧布局用在游戏开发中,显示自定义视图,我目前开发中用到的很少
在图片预览的时候用到过,其他的地方没有怎么用到过。
为了验证:
多个组件层叠排列,
后面的组件覆盖前面的组件, 我也写了一个经典的demo
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="300dp" android:layout_height="300dp" android:layout_gravity="center" android:background="#cc9900" android:text="小木"/> <TextView android:layout_width="200dp" android:layout_height="200dp" android:layout_gravity="center" android:background="#00ff00" android:text="小木"/> <TextView android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center" android:background="#ff00cc" android:text="小木"/> <TextView android:layout_width="50dp" android:layout_height="50dp" android:layout_gravity="center" android:background="#ffffff" android:text="小木"/> </FrameLayout>
三 AbsoluteLayout绝对布局
现在几乎不用了,用了它之后无法再进行适配了,原因吗?看下他的特点吧
特点:坐标的方式来定位在屏幕上的位置,引起缺乏灵活性,在没有绝对定位的情况下相比其他类型的布局更难维护
把刚才的代码拿来看看吧
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="300dp" android:layout_height="300dp" android:layout_gravity="center" android:background="#cc9900" android:text="小木"/> <TextView android:layout_width="200dp" android:layout_height="200dp" android:layout_gravity="center" android:background="#00ff00" android:text="小木"/> <TextView android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center" android:background="#ff00cc" android:text="小木"/> <TextView android:layout_width="50dp" android:layout_height="50dp" android:layout_gravity="center" android:background="#ffffff" android:text="小木"/> </AbsoluteLayout>
自己也是只有有这么一个布局,不过从来没有用到实际的项目中。