【ALearning】第四章 Android Layout组件布局(二)
前面我们分别介绍和学习了LinearLayout(线性布局)、FrameLayout(单帧布局)和AbsoluteLayout(绝对布局)。这次我们要进行RelativeLayout(相对布局)和TableLayout(表格布局)的学习。
这部分是非常重要的知识点。RelativeLayout是开发过程中强烈建议使用的,而TableLayout是满足一些特定需求时(常见表格显示,但不局限于此)须要使用。
【博客专栏:http://blog.csdn.net/column/details/alearning.html】
RelativeLayout(相对布局)
相对布局。顾名思义就是以“相对”位置/对齐为基础的布局方式。
本例拓展的属性配置是:
- android:id 指定该控件唯一标志的ID值;
- android:layout_above 指定该控件的底部置于给定ID的控件之上;
- android:layout_below 指定该控件的底部置于给定ID的控件之下;
- android:layout_toLeftOf 指定该控件的右边缘与给定ID的控件左边缘对齐;
- android:layout_toRightOf 指定该控件的左边缘与给定ID的控件右边缘对齐;
- android:layout_alignBaseline 指定该控件的baseline与给定ID的baseline对齐;
- android:layout_alignTop 指定该控件的顶部边缘与给定ID的顶部边缘对齐;
- android:layout_alignBottom 指定该控件的底部边缘与给定ID的底部边缘对齐;
- android:layout_alignLeft 指定该控件的左边缘与给定ID的左边缘对齐;
- android:layout_alignRight 指定该控件的右边缘与给定ID的右边缘对齐;
- android:layout_alignParentTop指定该控件的顶部与其父控件的顶部对齐;
- android:layout_alignParentBottom 指定该控件的底部与其父控件的底部对齐;
- android:layout_alignParentLeft 指定该控件的左部与其父控件的左部对齐;
- android:layout_alignParentRight 指定该控件的右部与其父控件的右部对齐;
注:相对布局的属相设置较多,在实际的开发中须要不断的补充与拓展。
<?xml version="1.0" encoding="utf-8"? >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- 该控件位于界面中部 -->
<TextView
android:id="@+id/red"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerInParent="true"
android:background="#CD2E57"
android:gravity="center"
android:text="Red" /> <!-- 该控件的左边缘与给定id为red控件的左边缘对齐 -->
<TextView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignLeft="@id/red"
android:background="#64DB99"
android:gravity="center"
android:text="Green" /> <!-- 该控件位于界面底部 同一时候 位于给定id为red控件的下边/右边(即右下位置) -->
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_below="@id/red"
android:layout_centerInParent="true"
android:layout_marginTop="20dp"
android:layout_toRightOf="@id/red"
android:background="#FFFA78"
android:gravity="center"
android:text="Yellow" /> <!-- 该控件位于给定id为red控件的左边 -->
<TextView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@id/red"
android:background="#148CFF"
android:gravity="center"
android:text="Blue" />
</RelativeLayout>
效果截图:
TableLayout(表格布局)
- android:stretchColumns 指定可伸展的列。该列能够向行方向伸展,最多可占领一整行。
- android:shrinkColumns 指定可收缩的列。当该列子控件的内容太多。已经挤满所在行,那么该子控件的内容将往列方向显示。
- android:collapseColumns 指定要隐藏的列。
演示样例:
android:stretchColumns="0" 第0列可伸展
android:shrinkColumns="1,2" 第1,2列皆可收缩
android:collapseColumns="*" 隐藏全部行
注:列能够同一时候具备stretchColumns及shrinkColumns属性。若此,那么当该列的内容N多时,将“多行”显示其内容。(这里不是真正的多行,而是系统依据须要自己主动调节该行的layout_height)。
- android:layout_column 指定该单元格在第几列显示
- android:layout_span 指定该单元格占领的列数(未指定时,为1)
演示样例:
android:layout_column="1" 该控件显示在第1列
android:layout_span="2" 该控件占领2列
说明:一个控件也能够同一时候具备这两个特性。
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="0,1,2" > <TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" > <TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#6495ED"
android:padding="2dp"
android:text="文本1-1" /> <TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#B0C4DE"
android:padding="2dp"
android:text="文本1-2" /> <TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#32CD32"
android:padding="2dp"
android:text="文本1-3" /> <TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#FFD700"
android:padding="2dp"
android:text="文本1-4" />
</TableRow> <TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" > <TextView
android:layout_height="40dp"
android:layout_column="1"
android:layout_span="2"
android:background="#FF8C00"
android:text="跨列文本2-2,3跨2到3列" />
</TableRow> <TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" > <TextView
android:layout_height="40dp"
android:layout_column="0"
android:layout_span="2"
android:background="#FF69B4"
android:text="跨列文本3-1,2跨1到2列" />
</TableRow> <!-- -->
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:collapseColumns="2"
android:shrinkColumns="1"
android:stretchColumns="0" > <TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" > <TextView
android:background="#696969"
android:textColor="@android:color/white"
android:text="行方向伸展文本,可自行增长文本查看效果!" /> <TextView
android:textColor="@android:color/white"
android:background="#800000"
android:text="列方向伸展文本,可自行增长文本查看效果!" />
</TableRow>
</TableLayout> </TableLayout>
效果截图:
这部分。将会在接下来的不断的学习中了解与使用。
敬请各位看官的继续关注。
參考资料
5、http://blog.csdn.net/beyond0525/article/details/8841139
【ALearning】第四章 Android Layout组件布局(二)的更多相关文章
- 【ALearning】第四章 Android Layout组件布局(一)
在本章中,我们将Android学习组件布局.在前面的章节,我们也开始使用LinearLayout布局.然后我们在布局文件更加具体的学习和理解,会. Android的界面是有布局和组件协同完毕的,布局好 ...
- 第四章Android移植环境搭建
第四章Android移植环境搭建 这一章主要学习如何搭建 Android 移植的环境.因为 Android 底层是基于 Linux 内核的,所以本章从交叉编译环境等嵌入式开发环境的搭建开始,介绍了 B ...
- 第四章 MySQL高级查询(二)
第四章 MySQL高级查询(二) 一.EXISTS子查询 在执行create 或drop语句之前,可以使用exists语句判断该数据库对像是否存在,返回值是true或false.除此之外,exists ...
- 【Android开发日记】之入门篇(四)——Android四大组件之Activity
在Android中,无论是开发者还是用户,接触最多的就算是Activity.它是Android中最复杂.最核心的组件.Activity组件是负责与用户进行交互的组件,它的设计理念在很多方面都和Web页 ...
- 第四章 android 命名规范和编码规范
书里面讲的比较常见,单个人也是有不同的观点: 因为android绝大部分使用java开发的,因此java相关规范适用于android: Google Style: 英文地址:http://google ...
- [Learn AF3]第四章 App framework组件之Button
Button 组件名称:Button 是否js控件:否 使用说明:如果说panel组件是af3的“核心(heart of the ui)”,那么Button就是af中的五虎上将之 ...
- android layout的布局
1.android:layout_width.android:layout_heigth 表示控件的大小,长宽 2.andoid:layout_gravity .android:gravity表示控件 ...
- Android笔记(五十四) Android四大组件之一——ContentProvider(一)
ContentProvider提供数据 在Android中,他的每个应用都是相互独立的,各自运行在自己的Dalvik虚拟机中,但现实使用中常常需要在多个应用之间进行数据交换,例如发短信需要获取联系人中 ...
- Android教材 | 第三章 Android界面事件处理(二)—— 杰瑞教育原创教材试读
编者按 JRedu 杰瑞教育原创系列教材将于年后与大家正式见面.为更好的借鉴读者意见,我们将会陆续地在博客园推出一系列教材试读.我们也热忱的欢迎广大博友与我们互动,提出宝贵意见. 本篇博客将推出教材 ...
随机推荐
- SKU=Stock Keeping Unit(库存量单位)。即库存进出计量的单位,可以是以件,盒,托盘等为单位
SKU=Stock Keeping Unit(库存量单位).即库存进出计量的单位,可以是以件,盒,托盘等为单位.SKU这是对于大型连锁超市DC(配送中心)物流管理的一个必要的方法.现在已经被引申为产品 ...
- class的写法
java中class的写法:1.public class xxx{}2.非public类:public class A{}public class B{}必须保证一个其中一个类名是public并与ja ...
- centos的dns配置总结
找的一篇好的存根 DNS正反向解析 DNS(Domain Name Service)域名服务.就是域名解析服务器.所谓名称解析的过程就是某个应用程序基于某个搜索键在指定的数据库中查询.而后查询到某些对 ...
- django框架初探
django框架初探 1.web框架介绍 web框架本质是一个socket服务端.每一个端口只能被一个程序监听. web程序分为两个部分: 服务器程序:对socket服务器封装,解析http请求,发送 ...
- ZOJ 3524 Crazy Shopping
Crazy Shopping Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ...
- Spring项目用junit 时出现org.junit.runners.BlockJUnit4ClassRunner cannot be resolved(转)
spring框架项目用junit做测试时,程序在自动编译时出现下述问题: 程序的问题是项目中找不到org.junit.runners.BlockJUnit4ClassRunner,有两种可能,一是没有 ...
- Tomcat之虚拟主机配置以及web应用配置
Tomcat之虚拟主机配置以及web应用配置 Tomcat文件夹结构例如以下: bin ---- 启动和关闭须要的bat文件所在的文件夹 conf --- 配置文件夹 lib --- tomcat执 ...
- Elasticsearch之es学习工作中遇到的坑(陆续更新)
1:es集群脑裂问题(不要用外网ip,节点角色不要混用) 原因1:阿里云服务器,外网有时候不稳定. 解决方案:单独采购服务器,内网安装 原因2:master和node节点没有分开 解决方案: 分角色: ...
- collapse折叠
基本: <button class="btn btn-primary" data-toggle="collapse" data-target=" ...
- 轻松学习Linux之详解系统引导过程
轻松学习Linux之详解系统引导过程-1 轻松学习Linux之详解系统引导过程-2 本文出自 "李晨光原创技术博客" 博客,谢绝转载!