【Android】7.5 RelativeLayout(相对布局)
分类:C#、Android、VS2015;
创建日期:2016-02-11
一、简介
RelativeLayout是一种相对布局,容器中子元素的位置是相对于其前一个元素或者其他元素的位置来计算的,或者是相对于其父容器的可填充区域来计算的。
1、什么时候使用相对布局
一般在嵌套的子区域中使用相对布局,这能显著提供性能,特别是多层嵌套的情况,要比用LinearLayout性能高得多。
记住:使用相对布局的唯一目的就是为了保持子元素间的相对位置不变。
2、常用属性
目标组件:用id指定。
度量单位:既可以是像素(例如30dip、40px),也可以是与像素无关的单位(dp)。
android:layout_above 在目标组件的上方
android:layout_alignBaseline 和目标组件的基线对齐。
android:layout_alignBottom 下边缘和目标组件的的下边缘对齐
android:layout_alignEnd 末端和目标组件末端对齐
android:layout_alignRight 右边缘和目标组件的的右边缘对齐
android:layout_alignLeft 左边缘和目标组件左边缘对齐
android:layout_alignStart 开始端和目标组件开始端对齐
android:layout_alignTop 顶部和目标组件的的顶部对齐
android:layout_below 在目标组件的下方
android:layout_toEndOf 在目标组件末端
android:layout_toLeftOf 在目标组件的左边
android:layout_toRightOf 在目标组件的右边
android:layout_alignLeft 在目标组件的开始端
3、与目标组件的对齐方式
由RelavieLayout.LayoutParams定义(true或false)。
android:layout_alignParentBottom 是否和父元素的底端对齐。
android:layout_alignParentEnd 是否和父元素的末端对齐。
android:layout_alignParentLeft 是否和父元素的左边对齐
android:layout_alignParentRight 是否和父元素的右边对齐
android:layout_alignParentStart 是否和父元素的开始对齐
android:layout_alignParentTop 是否和父元素的顶部对齐
android:layout_alignWithParentIfMissing 找不到目标元素是否以父元素做参照物
二、示例-- Demo04RelativeLayout
1、运行截图

2、添加Demo04RelativeLayout.axml文件
在Resources/layout文件夹下添加该文件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="请输入内容:" />
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/textView1" />
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editText1"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="确定" />
<Button
android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
android:text="取消" />
</RelativeLayout>
</LinearLayout>
3、添加Demo04RelativeLayout.cs文件
在SrcDemos文件夹下添加该文件。
using Android.App;
using Android.OS;
using Android.Widget; namespace ch07demos.SrcDemos
{
[Activity(Label = "Demo04RelativeLayout")]
public class Demo04RelativeLayout : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Demo04RelativeLayout);
FindViewById<Button>(Resource.Id.ok).Click += delegate
{
Toast.MakeText(this, "你单击了[确定]", ToastLength.Long).Show();
};
FindViewById<Button>(Resource.Id.cancel).Click += delegate
{
Toast.MakeText(this, "你单击了[取消]", ToastLength.Long).Show();
};
}
}
}
【Android】7.5 RelativeLayout(相对布局)的更多相关文章
- Android之控件与布局,结构知识点,基础完结
版权声明:未经博主允许不得转载 在Android中我们常常用到很多UI控件,如TextView,EditText,ImageView,Button,ImageButton,ToggleButton,C ...
- Android开发重点难点1:RelativeLayout(相对布局)详解
前言 啦啦啦~博主又推出了一个新的系列啦~ 之前的Android开发系列主要以完成实验的过程为主,经常会综合许多知识来写,所以难免会有知识点的交杂,给人一种混乱的感觉. 所以博主推出“重点难点”系列, ...
- Android开发3:Intent、Bundle的使用和ListView的应用 、RelativeLayout(相对布局)简述(简单通讯录的实现)
前言 啦啦啦~博主又来骚扰大家啦~大家是不是感觉上次的Android开发博文有点长呢~主要是因为博主也是小白,在做实验的过程中查询了很多很多概念,努力去理解每一个知识点,才完成了最终的实验.还有就是随 ...
- Android(java)学习笔记164:Relativelayout相对布局案例
我们看看案例代码,自己心领神会: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout ...
- android LinearLayout和RelativeLayout实现精确布局
先明确几个概念的区别: padding margin:都是边距的含义,关键问题得明白是什么相对什么的边距padding:是控件的内容相对控件的边缘的边距. margin :是控件边缘相对父空间的边距 ...
- 第13章、布局Layouts之RelativeLayout相对布局(从零開始学Android)
RelativeLayout相对布局 RelativeLayout是一种相对布局,控件的位置是依照相对位置来计算的,后一个控件在什么位置依赖于前一个控件的基本位置,是布局最经常使用,也是最灵活的一种布 ...
- 从零開始学android<RelativeLayout相对布局.十六.>
相对布局管理器指的是參考某一其它控件进行摆放,能够通过控制,将组件摆放在一个指定參考组件的上.下.左.右等位置,这些能够直接通过各个组件提供的属性完毕. 以下介绍一下各个方法的基本使用 No. 属性名 ...
- 用android LinearLayout和RelativeLayout实现精确布局(转)
先明确几个概念的区别: padding margin都是边距的含义,关键问题得明白是什么相对什么的边距. padding是控件的内容相对控件的边缘的边距. margin是控件边缘相对父控件的边距. a ...
- [转]用android LinearLayout和RelativeLayout实现精确布局
先明确几个概念的区别: padding margin都是边距的含义,关键问题得明白是什么相对什么的边距. padding是控件的内容相对控件的边缘的边距. margin是控件边缘相对父控件的边距. a ...
- Android精通:TableLayout布局,GridLayout网格布局,FrameLayout帧布局,AbsoluteLayout绝对布局,RelativeLayout相对布局
在Android中提供了几个常用布局: LinearLayout线性布局 RelativeLayout相对布局 FrameLayout帧布局 AbsoluteLayout绝对布局 TableLayou ...
随机推荐
- Python标记去重
预逻辑脚本代码: uniqueList = [] def isDuplicate(inValue): if inValue in uniqueList: return 1 else: uniqueLi ...
- 分离链接散列表C语言实现实例
/* hash_sep.h */ #ifndef _HASH_SEP_H #define _HASH_SEP_H #define MIN_TABLE_SIZE 5 struct list_node; ...
- android:View的setTag和getTag使用
1.用于区分非常多类似的View 比如: button1.setOnClickListener(new OnClickListener ... ); button2.setOnClickListene ...
- jquery获取td所在的行和列
今天在做项目时.遇到一个须要获取第几行第几列的问题. 后来.网上找了找资料,整理了此文.(使用jquery的preAll()获取列) 代码例如以下: <!DOCTYPE html PUBLIC ...
- 解决a标签IE下点击后出现轮廓框
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Loadrunner脚本编程(3)- 检查点,关联等函数
http://www.360doc.com/content/10/0806/13/1698198_44078093.shtml 1. 错误预防和恢复 参数默认是用{}括起来的,但也可以指定用< ...
- RDD转换成DataFrames
官方提供了2种方法 1.利用反射来推断包含特定类型对象的RDD的schema.这种方法会简化代码并且在你已经知道schema的时候非常适用. 先创建一个bean类 case class Person( ...
- Windwos在cmd如何复制文本
生活的琐事,总是要解决. 01.Win+R打开运行窗口 cmd--回车 02. 勾选快速编辑模式 注意: 快速编辑模式就是可以Ctrl+c(复制).Ctrl+v(粘贴)
- VS2010没有Intellisense(智能感知)的解决办法
VS2010没有Intellisense(智能感知)的解决办法 Visual Studio 2010 的Intellisense是依赖于Microsoft SQL Server Compact 3.5 ...
- Linux命令行上执行操作,不退回命令行的解决方法
问题描述: 如果你现在登录Centos执行了某个操作,但是操作一直占用命令行,命令行显示的也都是这个命令相关的操作,我想做其它事情 ,该怎么办呢 ? 解决方法: 根据<Linux命令行与Shel ...