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).通常使用菜单资源 ...
随机推荐
- hdu 4973 A simple simulation problem. (线段树)
题目链接 题意: 给定n长的序列 m个操作 序列默认为 1, 2, 3···n 操作1:D [l,r] 把[l,r]区间增长 :( 1,2,3,4 进行 D [1,3]变成 1,1,2,2,3,3,4 ...
- HDU 4965 矩阵快速幂
顺手写了下矩阵类模板 利用到矩阵乘法的交换律 (A*B)^n == A * (B*A)^n-1 *B #include <cstdio> #include <cstring> ...
- GridView CommandArgument 绑定多个参数
我们在使用GridView的时候 有时会需要绑定多个参数 <asp:GridView ID="gvwVoxListAll" runat="server" ...
- Java Web编程的主要组件技术——MVC设计模式
参考书籍:<J2EE开源编程精要15讲> MVC(Model View Controller),Model(模型)表示业务逻辑层,View(视图)代表表述层,Controller(控制)表 ...
- 【html】页面制作规范文档
每天都在写html/css/js代码,总结的一些页面制作的规范 文件命名规范 1) 文件目录.文件名称统一用小写的英文字母.数字.下划线组合,文件名要与表现的内容相近,不到万不得已不要以拼音作为名称, ...
- Linux如何统计进程的CPU利用率
1.0 概述 在Linux的/proc文件系统,可以看到自启动时候开始,所有CPU消耗的时间片:对于个进程,也可以看到进程消耗的时间片.这是一个累计值,可以"非阻塞"的输出.获得一 ...
- C# 总结
转自原文 C# 总结 1.类型是隐式内部的.(类) 2.类型成员是隐式私有的.(方法) 3.常量定义:const 是隐式static的,必须在定义时设置初始值. 4.只读字段:readonly 可以在 ...
- CodeForces 54C-First Digit Law(数位,概率dp)
题意: 给你n个区间,在每个区间里各取一个数(随机取),求这n个数中超过K%的数是首位为1数的概率 分析: dp[i][j]取前i个数,有j个是首位为1的数的概率 易知,dp[i][j]=dp[i-1 ...
- javascript 面向对象整理
整理一下js面向对象中的封装和继承. 1.封装 js中封装有很多种实现方式,这里列出常用的几种. 1.1 原始模式生成对象 直接将我们的成员写入对象中,用函数返回. 缺点:很难看出是一个模式出来的实例 ...
- ASP.NET MVC中的Json Binding和Validate
引子:电子商务网站支付功能页面往往会有很多信息,对于这些信息的保存,往往是分步完成的,那么使用Ajax最合适不过了,比如其中的收货人信息模块.这些信息的新建和编辑保存都是用Ajax来完成的.那么有几种 ...