【Android开发学习笔记】【第八课】五大布局-下
概念
五大布局上一篇文章已经介绍了
LinearLayout
RelativeLayout
这一篇我们介绍剩下的三种布局
FrameLayout
五种布局中最佳单的一种布局。在这个布局在整个界面被当成一块空白区域,所有的子元素不能放倒指定的位置,只能放到这个区域的左上角,并且后面的子元素会直接覆盖前面的子元素。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff000000"
android:gravity="center"
android:text="1" /> <TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff654321"
android:gravity="center"
android:text="2" /> <TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#fffedcba"
android:gravity="center"
android:text="3" /> </FrameLayout>
上面的布局文件的效果:
第一个TextView被第二个TextView完全遮挡,第三个TextView遮挡了第二个TextView的部分位置

AbsoluteLayout 绝对位置布局
顾名思义,在此布局在子元素的android:layout_x和android:layout_y属性将生效,用于描述该子元素的坐标位置。屏幕左上角为坐标原点(0,0),第一个0代表横坐标,向右移动此值增大,第二个0代表纵坐标,向下移动,此值增大。在此布局中的子元素可以相互重叠。在实际开发中,通常不采用此布局格式,因为它的界面代码过于刚性,以至于有可能不能很好的适配各种终端。
<AbsoluteLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_x="50dp"
android:layout_y="50dp"
android:background="#ff11ffff"
android:gravity="center"
android:text="1" /> <TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_x="25dp"
android:layout_y="25dp"
android:background="#ff654321"
android:gravity="center"
android:text="2" /> <TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_x="125dp"
android:layout_y="125dp"
android:background="#fffedcba"
android:gravity="center"
android:text="3" /> </AbsoluteLayout>
显示效果如下:

TableLayout 表格布局
适用于N行N列的布局方式。一个TableLayout由许多TableRow组成,一个TableRow就代表TableLayout中的一行。
TableRow是LinearLayout的子类,它的android:orientation属性值恒为horizontal,并且它的android:layout_width和android:layout_height属性值恒为MATCH_PARENT和WRAP_CONTENT。
所以它的子元素都是横向排列,并且宽高一致的。
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <TextView
android:background="#ff11ffff"
android:gravity="center"
android:padding="10dp"
android:text="1" /> <TextView
android:background="#ff654321"
android:gravity="center"
android:padding="10dp"
android:text="2" /> <TextView
android:background="#fffedcba"
android:gravity="center"
android:padding="10dp"
android:text="3" />
</TableRow> <TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <TextView
android:background="#ff654321"
android:gravity="center"
android:padding="10dp"
android:text="2" /> <TextView
android:background="#fffedcba"
android:gravity="center"
android:padding="10dp"
android:text="3" />
</TableRow> <TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <TextView
android:background="#fffedcba"
android:gravity="center"
android:padding="10dp"
android:text="3" /> <TextView
android:background="#ff654321"
android:gravity="center"
android:padding="10dp"
android:text="2" /> <TextView
android:background="#ff11ffff"
android:gravity="center"
android:padding="10dp"
android:text="1" />
</TableRow> </TableLayout>
这样的设计使得每个TableRow里的子元素都相当于表格中的单元格一样。
在TableRow中,单元格可以为空,但是不能跨列。
下面示例演示了一个TableLayout的布局结构,其中第二行只有两个单元格,而其余行都是三个单元格。

【Android开发学习笔记】【第八课】五大布局-下的更多相关文章
- 【Android开发学习笔记之一】5大布局方式详解
Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):按照垂直或者水平方向布局的组件. 帧布局(FrameLayout):组件从屏幕左上方布局组件. 表格布局(Tabl ...
- android开发学习笔记000
使用书籍:<疯狂android讲义>——李刚著,2011年7月出版 虽然现在已2014,可我挑来跳去,还是以这本书开始我的android之旅吧. “疯狂源自梦想,技术成就辉煌.” 让我这个 ...
- 【转】Android开发学习笔记:5大布局方式详解
Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):按照垂直或者水平方向布局的组件. 帧布局(FrameLayout):组件从屏幕左上方布局组件. 表格布局(Tabl ...
- 【前端】移动端Web开发学习笔记【2】 & flex布局
上一篇:移动端Web开发学习笔记[1] meta标签 width设置的是layout viewport 的宽度 initial-scale=1.0 自带 width=device-width 最佳实践 ...
- 【Android开发学习笔记】【第七课】五大布局-上
概念 Android程序各式各样,依靠的就是布局,先来看看布局都是怎么来的: 白色部分就是我们经常用的几种布局,主要说说介绍下面五大布局 FrameLayout AbsoluteLayout Line ...
- android开发学习笔记系列(2)-android应用界面编程
前言 本篇博客将会简要介绍andriod开发过程中的一些界面元素和编程的实现,我将大家走进安卓的XML世界,当然可能会涉及到java代码,当然本文主要是介绍XML文件的界面布局. 那么我们的XML存在 ...
- android开发学习笔记系列(1)-android起航
前言 在学习安卓的过程中,我觉得非常有必要将自己所学的东西进行整理,因为每每当我知道我应该是如何去实现功能的时候,有许多细节问题我总是会遗漏,因此我也萌生了写一系列博客来描述自己学习的路线,让我的an ...
- 【转】Android开发学习笔记(一)——初识Android
对于一名程序员来说,“自顶向下”虽然是一种最普通不过的分析问题和解决问题的方式,但其却是简单且较为有效的一种.所以,将其应用到Android的学习中来,不至于将自己的冲动演变为一种盲目和不知所措. 根 ...
- Android开发学习笔记DDMS的使用
打开DDMS DDMS 的全称是Dalvik Debug Monitor Service,是 Android 开发环境中的Dalvik虚拟机调试监控服务. DDMS里面包含了:Device(设备) F ...
随机推荐
- 使用OUYA第一次启动OUYA
使用OUYA第一次启动OUYA 1.4 使用OUYA 初次使用OUYA时,其启动以后的设置过程耗时较长,也比较繁琐,因此本节将会对其做个详细介绍,让读者的使用过程更加顺利些!好的开端总归是一个不错的 ...
- 一个DIV三列布局100%高度自适应的好例子(国外)
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W ...
- 使用“Empty 模式”改进 Null Object
概述 Null Object 是Martin 大师提出的一种重构手段,其思想就是通过多态(派生一个Null对象)来减少逻辑(if … then …else)的判断. 而.NET中已经有Null Obj ...
- Eddy's problem partI
Eddy's mistakes[HDU1161] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 【BZOJ】1603: [Usaco2008 Oct]打谷机(水题+dfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1603 这种水题... dfs没话说.. #include <cstdio> #inclu ...
- CentOS 下实现两台服务器之间的共享NFS
NFS的安装配置:centos 5 :yum install nfs-utils portmapcentos 6 :yum install nfs-utils rpcbind yum install ...
- oracle 存储过程 基础
差不多一年没写过存储过程,最近要写,发现基本忘了,google一番之后,觉得很有必要把基础的东西写下来备忘. 语句块定义: decalre -- 变量声明 var1 ); -- 仅声明 var2 ) ...
- iOS移动开发周报-第21期
iOS移动开发周报-第21期 [摘要]:本期iOS移动开发周报带来如下内容:苹果iCloud中国数据转存中国电信,Swift Operators,100 个 Swift 必备 tips,FLEXLoa ...
- PHP多重判断删除文件函数
<?function delete_file($file) { if (file_exists($file)) { $delete = chmod ($file, ...
- gnuplotx轴的logscale显示
假设数据是这样子的: gnuplot脚本如下: set terminal postscript eps color enhanced set log x set log y set format x ...