Android应用开发学习之相对布局
作者:刘昊昱
博客:http://blog.csdn.net/liuhaoyutz
相对布局RelativeLayout是指按照组件之间的相对位置进行布局,如一个组件在另一个组件的左边、右边、上边或下边等。
RelativeLayout常用的XML属性有:
android:gravity
用于设置布局管理器中各子组件的对齐方式。
android:ignoreGravity
用于指定哪个组件不受gravity属性的影响。
在相对布局管理器中,如果只有上面两个属性是远远不够的,为了更好地控制该布局管理器中的组件,RelativeLayout提供了一个内部类:RelativeLayout.LayoutParams,通过该类提供的大量XML属性,可以很好的控制RelativeLayout中的各组件的布局。
下表是Android官方网站上给出的RelativeLayout.LayoutParams的XML属性
|
Attribute Name |
Description |
|
Positions the bottom edge of this view above the given anchor view ID. |
|
|
Positions the baseline of this view on the baseline of the given anchor view ID. |
|
|
Makes the bottom edge of this view match the bottom edge of the given anchor view ID. |
|
|
Makes the end edge of this view match the end edge of the given anchor view ID. |
|
|
Makes the left edge of this view match the left edge of the given anchor view ID. |
|
|
If true, makes the bottom edge of this view match the bottom edge of the parent. |
|
|
If true, makes the end edge of this view match the end edge of the parent. |
|
|
If true, makes the left edge of this view match the left edge of the parent. |
|
|
If true, makes the right edge of this view match the right edge of the parent. |
|
|
If true, makes the start edge of this view match the start edge of the parent. |
|
|
If true, makes the top edge of this view match the top edge of the parent. |
|
|
Makes the right edge of this view match the right edge of the given anchor view ID. |
|
|
Makes the start edge of this view match the start edge of the given anchor view ID. |
|
|
Makes the top edge of this view match the top edge of the given anchor view ID. |
|
|
If set to true, the parent will be used as the anchor when the anchor cannot be be found for layout_toLeftOf, layout_toRightOf, etc. |
|
|
Positions the top edge of this view below the given anchor view ID. |
|
|
If true, centers this child horizontally within its parent. |
|
|
If true, centers this child horizontally and vertically within its parent. |
|
|
If true, centers this child vertically within its parent. |
|
|
Positions the start edge of this view to the end of the given anchor view ID. |
|
|
Positions the right edge of this view to the left of the given anchor view ID. |
|
|
Positions the left edge of this view to the right of the given anchor view ID. |
|
|
Positions the end edge of this view to the start of the given anchor view ID. |
下面我们来看一个例子,该程序运行效果如图所示:
我们来看该程序的主布局文件main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<!-- 添加一个居中显示的文本视图textView1 -->
<TextView android:text="您正在学习RelativeLayout的用法 ,是否开始动手练习?"
android:id="@+id/textView1"
android:textSize="24px"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
/>
<!-- 添加一个在button2左侧显示的按钮button1 -->
<Button
android:text="开始练习"
android:id="@+id/button1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@+id/textView1"
android:layout_toLeftOf="@+id/button2"
/>
<!-- 添加一个按钮button2,该按钮与textView1的右边界对齐 -->
<Button
android:text="不练习"
android:id="@+id/button2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignRight="@+id/textView1"
android:layout_below="@+id/textView1"
/>
</RelativeLayout>
通过这个例子,我们可以理解相对布局控件RelativeLayout的用法了。
Android应用开发学习之相对布局的更多相关文章
- Android应用开发学习之表格视图
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 本文我们来学习一个使用表格视图的程序,下图是该程序的运行效果: 该程序主Activity文件内容如下: packag ...
- 2021年正确的Android逆向开发学习之路
2021年正确的Android逆向开发学习之路 说明 文章首发于HURUWO的博客小站,本平台做同步备份发布.如有浏览或访问异常或者相关疑问可前往原博客下评论浏览. 原文链接 2021年正确的Andr ...
- Android应用开发学习笔记之绘图
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 一.绘图常用类介绍 在Android中绘图时,常用到的几个类是Paint.Canvas.Bitmap和Bitmapt ...
- Android应用开发学习笔记之播放音频
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz Android支持常用音视频格式文件的播放,本文我们来学习怎样开发Android应用程序对音视频进行操作. Andr ...
- Android 系统开发学习杂记(转)
http://blog.csdn.net/shagoo/article/details/6709430 > 开发环境1.安装 Eclipse 和 android-sdk 并解压安装2.Eclip ...
- Android应用开发学习笔记之AsyncTask
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 在上一篇文章中我们学习了多线程和Handler消息处理机制,如果有计算量比较大的任务,可以创建一个新线程执行计算工作 ...
- android移动开发学习笔记(二)神奇的Web API
本次分两个大方向去讲解Web Api,1.如何实现Web Api?2.如何Android端如何调用Web Api?对于Web Api是什么?有什么优缺点?为什么用WebApi而不用Webservice ...
- Android应用开发学习笔记之Fragment
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz Fragment翻译成中文就是“碎片”.“片断”的意思,Fragment通常用来作为一个Activity用户界面的一 ...
- Android应用开发学习笔记之菜单
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz Android中的菜单分为选项菜单(OptionMenu)和上下文菜单(Context Menu).通常使用菜单资源 ...
随机推荐
- org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml at org.hibernate ...
- UVa 10817 (状压DP + 记忆化搜索) Headmaster's Headache
题意: 一共有s(s ≤ 8)门课程,有m个在职教师,n个求职教师. 每个教师有各自的工资要求,还有他能教授的课程,可以是一门或者多门. 要求在职教师不能辞退,问如何录用应聘者,才能使得每门课只少有两 ...
- js对联广告代码,兼容性高
var browser = { ie6: function () { return ((window.XMLHttpRequest == undefined) && (ActiveXO ...
- asp.net正则表达式过滤标签和数据提取
无论什么语言,正则表达式的处理方法都是非常灵活.高效的,尤其是对某些字符串的抓取.过滤方面,更显其优势. 正则表达式的写法通常比较简单,几行短代码便能轻松完成看似很复杂的事情,更值得称赞的是,它的执行 ...
- listview默认选择第一项,点击换子项背景图
(不是大神,没有几百子项目,去你丫的) private int last_item_position ; @Override public void onItemClick(AdapterView&l ...
- liunx下mysql数据库使用之三范式,关系模型设计注意项,安装目录结构
数据库的三范式第一范式===>每行记录的属性,是原子的,拆到不可拆为止.===>例如:一个人的籍贯,可以拆分为,省,市,县,乡,村 第二范式===>每行记录的非主属性(非主键属性), ...
- 【LCS,LIS】最长公共子序列、单调递增最长子序列
单调递增最长子序列 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 求一个字符串的最长递增子序列的长度如:dabdbf最长递增子序列就是abdf,长度为4 输入 ...
- 30种oracle常见的等待事件说明
1Buffer busy waits从本质上讲,这个等待事件的产生仅说明了一个会话在等待一个Buffer(数据块),但是导致这个现象的原因却有很多种.常见的两种是: 当一个会话视图修改一个数据块,但这 ...
- 安装--SambaServce
参考地址:快跑蚂蚁的linux之旅--redhat安装配置samba实验win共享linux主机目录 1.使用rpm -qa|grep "samba",查看samba安装包是否安装 ...
- @section Right
布局页 _BaseLayout.cshtml @RenderSection("Right", true) 视图页 Index.cshtml @{ Layout = "~/ ...