【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 ...
随机推荐
- storm0.9.0.1升级安装
来自:http://blog.csdn.net/liuzhoulong/article/details/21112101 1,下载0.9.0.1 http://storm.incubator.apac ...
- Adaptive Thresholding & Otsu’s Binarization
Adaptive Thresholding Adaptive Method - It decides how thresholding value is calculated. cv2.ADAPTIV ...
- Redis学习(7)-通用命令
keys pattern: 获取所有与pattern匹配的key,返回所有与该key匹配的keys. 通配符: *表示任意一个或多个字符串. ?表示一个字符. 例如: 查询所有的key:keys * ...
- 自定义AppServer
TelnetSever.cs public class TelnetServer : AppServer<TelnetSession> { protected override bool ...
- 为什么WEB-INF外的jsp无法根据cookie享受国际化
243行走WEB-INF外则获取为空,走springmvc则可以获取到:
- 从零开始学做微信小程序,看这些就够了!
随着正式开放公测,微信小程序再次万众瞩目,越来越多的企业和个人涌入到小程序开发的大军中.小程序究竟是什么?适合做小程序的产品有哪些?做小程序需要提前准备什么?如何零基础学做小程序?此文,将列出OSC上 ...
- bzoj1296【SCOI2009】粉刷匠
1296: [SCOI2009]粉刷匠 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 1479 Solved: 837 [id=1296" ...
- Web Service基础——四种客户端调用方式
通过访问公网服务地址 http://www.webxml.com.cn/zh_cn/index.aspx 来演示四种不同的客户端调用方式 1. 生成客户端调用方式 1.1 Wsimport命令介绍 首 ...
- HDUOJ---1754 Minimum Inversion Number (单点更新之求逆序数)
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- C++知识整理(进制)
++输出二进制.十进制.八进制和十六进制总结 分类: C++ 2013-01-14 02:26 592人阅读 评论(0) 收藏 举报 在C++中,默认状态下,数据按十进制输入输出.如果要求按八进制或十 ...