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).通常使用菜单资源 ...
随机推荐
- SQL查看数据库所用用户表数量和使用的空间
SQL Server数据库管理员通常硬盘空间奋斗,不断努力清理“表”,撰写许多查询,发现该表使用的硬盘空间. 本文介绍了如何查询系统表的空间使用情况,帮助数据库管理员识别正在使用最多的空间,以便存档旧 ...
- Redis必要的一些配置
[root@localhost202 redis-2.8.19]# /usr/local/redis/bin/redis-server >> /data/redis-start.txt ...
- 用户输入 i. 检测常用手势(一)
参考: http://blog.csdn.net/qq418716640/article/details/8508973http://www.cnblogs.com/mengdd/p/3335508. ...
- Fragemnt
1. 创建一个Fragment 一个空的 FrameLayout作为fragment的容器 article_view.xml <FrameLayout xmlns:android="h ...
- php.ini配置中文详解
;;;;;;;;;;; ; 警告 ; ;;;;;;;;;;; ; 此配置文件是对于新安装的PHP的默认设置. ; 默认情况下,PHP使用此配置文件安装 ; 此配置针对开发目的,并且*不是*针对生产环境 ...
- IPicture、BITMAP、HBITMAP和CBitmap的关系
1.有关IPicture加载图片后直接Render到内存DC的问题(HBITMAP转换IPicture)Picture的方法get_Handle可以直接得到图片的句柄 IPicture *pIPict ...
- 【JS】js获得下拉列表选中项的值和id
function tijiao(){ var elem = document.getElementById("dish_sort"); var index=elem.selecte ...
- Oracle 课程八之跟踪事件set event
一.Oracle跟踪文件 Oracle跟踪文件分为三种类型: 一种是后台报警日志文件,记录数据库在启动.关闭和运行期间后台进程的活动情况,如表空间创建.回滚段创建.某些alter命令.日志切换.错误消 ...
- 《Python基础教程(第二版)》学习笔记 -> 第八章 异常
什么是异常 Python用 异常对象(exception object)来表示异常情况.遇到错误后,会引发异常,如果异常对象并未被处理或者捕捉,程序就会用所谓的回溯(Traceback,一种错误信息) ...
- 纯CSS3实现宽屏二级下拉菜单
今天我们要来分享一款基于纯CSS3的宽屏二级下拉菜单,这款菜单的子菜单在展开的时候是很宽敞的,菜单项中可以自定义格式的内容,非常实用,也很大气.由于是用纯CSS3实现,所以这款下拉菜单不用运行Java ...