【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 ...
随机推荐
- Java8新特性 - Lambda表达式 - 基本知识
A lambda expression is an unnamed block of code (or an unnamed function) with a list of formal param ...
- C# 编程实现串口通信
http://blog.sina.com.cn/s/blog_6c67dab30101p3vn.html ----------------------------------------------- ...
- html页面禁止选择复制剪切
在body加入 onselectstart="return false" oncopy="return false;" oncut="return f ...
- apachebench的简单使用
apachebench的简单使用 2013-03-08 15:48:47 分类: LINUX ApacheBench是 Apache 附带的一个小工具,专门用于 HTTP Server 的benchm ...
- [转载]linux创建用户命令
原文地址:linux创建用户命令作者:疯狂的核桃 创建用户.设置密码.修改用户.删除用户: useradd testuser 创建用户testuser passwd testuser 给已创建 ...
- MyEclipse 8.6插件下载
(源自网络:http://hi.baidu.com/%D4%B5%BA%A3%C7%E9%C9%EE/blog/item/ad86323d1e80a5e33d6d97c6.html 和 http:/ ...
- poj----2155 Matrix(二维树状数组第二类)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 16950 Accepted: 6369 Descripti ...
- Android Developers:使ListView滑动流畅
流畅滑动ListView的关键是保持应用程序的主线程(UI线程)从免于繁重处理.确保你的任何硬盘访问,网络访问或者SQL访问在一个单独的线程中.为了测试你的应用个程序的状态,你能启动StrictMod ...
- Android Fragment之间传递List数据
要说的是在两个Fragment之间传递List数据,比如有个List<User>,以及传递字符串数据,比如testId,该如何从FragmentA传递到FragmentB呢? 下面这个例子 ...
- 转: Python中的os.path.dirname(__file__)
(1).当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如: ...