一、相对于父容器

1.居中

2.同方向

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <!--相对于父容器
1.居中
2.同方向对齐方式
-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮一"
android:layout_centerInParent="true"
/><!--位于父容器居中位置-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮二"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/><!--与父容器底端对齐-->
<!--位于父容器水平居中位置-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮三"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
/><!--与父容器右侧对齐-->
<!--位于父容器垂直居中位置-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮四"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
/><!--与父容器左侧对齐-->
<!--位于父容器垂直居中位置-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮五"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/><!--与父容器顶端对齐-->
<!--位于父容器水平居中位置-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮六"
/><!--与父容器左侧对齐-->
<!--与父容器顶端对齐-->
<!--默认位置-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮七"
android:layout_alignParentRight="true"
/><!--与父容器右侧对齐-->
<!--与父容器顶端对齐-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮八"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/><!--与父容器左侧对齐-->
<!--与父容器底端对齐-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮十"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
/><!--与父容器右侧对齐-->
<!--与父容器底端对齐-->
</RelativeLayout>

二、与兄弟组件的相对位置

1.同方向

2.反方向

+lay_outmargin +padding

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--与兄弟组件之间
1.同方向
2.反方向--> <!--margin 外边距
padding 内间距
-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮一"
android:layout_centerInParent="true"
android:id="@+id/bt"/><!--父容器内居中-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮二"
android:layout_alignTop="@id/bt"
android:layout_toLeftOf="@id/bt"/>
//相对于按钮一 顶部对齐 位于左侧 <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮三"
android:layout_alignRight="@id/bt"
android:layout_above="@id/bt"/>
//相对于按钮一 右侧对齐 位于上方
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮四"
android:layout_alignRight="@id/bt"
android:layout_below="@id/bt"/>
//相对于按钮一 右侧对齐 位于下方
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮五"
android:layout_alignTop="@id/bt"
android:layout_toRightOf="@id/bt"/>
//相对于按钮一 顶部对齐 位于右侧
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮六"
android:layout_toRightOf="@id/bt"
android:layout_below="@id/bt"/>
//相对于按钮一 位于右侧 位于下方
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮七"
android:layout_toRightOf="@id/bt"
android:layout_above="@id/bt"/>
//相对于按钮一 位于右侧 位于上方 <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮八"
android:layout_toLeftOf="@id/bt"
android:layout_above="@id/bt"/>
//相对于按钮一 位于左侧 位于上方 <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮九"
android:layout_toLeftOf="@id/bt"
android:layout_below="@id/bt"/>
//相对于按钮一 位于左侧 位于下方
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="输入框"
android:id="@+id/et"
android:paddingLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"/>
//内左侧间距20dp 上边距20dp 下边距10dp <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
android:layout_alignParentRight="true"
android:layout_below="@id/et"
android:id="@+id/ok"/>
//ok按钮 位于父窗口右侧 输入框下方
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CANCLE"
android:layout_alignTop="@id/ok"
android:layout_toLeftOf="@id/ok"
android:layout_marginRight="20dp"/>
//cancle按钮 相对于ok按钮顶部对齐 位于左侧 右边距20dp </RelativeLayout>

Android——RelativeLayout(相对布局)的更多相关文章

  1. Android RelativeLayout相对布局

    RelativeLayout是相对布局控件:以控件之间相对位置或相对父容器位置进行排列. 相对布局常用属性: 子类控件相对子类控件:值是另外一个控件的id android:layout_above-- ...

  2. Android开发重点难点1:RelativeLayout(相对布局)详解

    前言 啦啦啦~博主又推出了一个新的系列啦~ 之前的Android开发系列主要以完成实验的过程为主,经常会综合许多知识来写,所以难免会有知识点的交杂,给人一种混乱的感觉. 所以博主推出“重点难点”系列, ...

  3. Android开发3:Intent、Bundle的使用和ListView的应用 、RelativeLayout(相对布局)简述(简单通讯录的实现)

    前言 啦啦啦~博主又来骚扰大家啦~大家是不是感觉上次的Android开发博文有点长呢~主要是因为博主也是小白,在做实验的过程中查询了很多很多概念,努力去理解每一个知识点,才完成了最终的实验.还有就是随 ...

  4. Android(java)学习笔记164:Relativelayout相对布局案例

    我们看看案例代码,自己心领神会: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout ...

  5. 第13章、布局Layouts之RelativeLayout相对布局(从零開始学Android)

    RelativeLayout相对布局 RelativeLayout是一种相对布局,控件的位置是依照相对位置来计算的,后一个控件在什么位置依赖于前一个控件的基本位置,是布局最经常使用,也是最灵活的一种布 ...

  6. Android开发之布局--RelativeLayout布局

    RelativeLayout 相对布局 true或false属性 Layout_centerHorizontal   当控件位于父控件的横向中间位置 Layout_centerVertical   当 ...

  7. Android精通:TableLayout布局,GridLayout网格布局,FrameLayout帧布局,AbsoluteLayout绝对布局,RelativeLayout相对布局

    在Android中提供了几个常用布局: LinearLayout线性布局 RelativeLayout相对布局 FrameLayout帧布局 AbsoluteLayout绝对布局 TableLayou ...

  8. Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件

    UI的描述 对于Android应用程序中,所有用户界面元素都是由View和ViewGroup对象构建的.View是绘制在屏幕上能与用户进行交互的一个对象.而对于ViewGroup来说,则是一个用于存放 ...

  9. Android(java)学习笔记107:Relativelayout相对布局

    1. Relativelayout相对布局案例: 我们看看案例代码,自己心领神会: <?xml version="1.0" encoding="utf-8" ...

随机推荐

  1. 图结构练习——BFS——从起始点到目标点的最短步数(邻接表+BFS)

    图练习-BFS-从起点到目标点的最短步数 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 在古老的魔兽传说中.有两个军团,一个 ...

  2. 关于C#程序优化的五十种方法

    关于C#程序优化的五十种方法    这篇文章主要介绍了C#程序优化的五十个需要注意的地方,使用c#开发的朋友可以看下   一.用属性代替可访问的字段 1..NET数据绑定只支持数据绑定,使用属性可以获 ...

  3. (C++)C++类继承中的构造函数和析构函数

    思想: 在C++的类继承中, 建立对象时,首先调用基类的构造函数,然后在调用下一个派生类的构造函数,依次类推: 析构对象时,其顺序正好与构造相反: 例子: #include <iostream& ...

  4. C#应用视频教程3.1 USB工业相机测试

    图像处理是工控很有价值的一个领域,比如人脸识别,车牌识别,还有产品的位置识别,瑕疵检测,对于个人学习来说,我们无法直接上手几万块的成熟工业相机(高端的康耐视要6万左右,而且是黑白的,要测试一些带颜色的 ...

  5. 双硬盘Win7装Ubuntu 12.04经验并解决无线网络不能使用问题

    RFKill Many computer systems contain radio transmitters, including Wi-Fi, Bluetooth, and 3G devices. ...

  6. 初次使用IntelliJ IDEA

    一.认识IDEA IDEA 全称IntelliJ IDEA,是java语言开发的集成环境,IntelliJ在业界被公认为最好的java开发工具之一,尤其在智能代码助手.代码自动提示.重构.J2EE支持 ...

  7. 转 SqlServer中如何实现自动备份数据!

    第1种方法: 企业管理器  --管理  --右键数据库维护计划  --新建维护计划  --<下一步>  --选择你要备份的数据库  --<下一步>直到"指定数据库备份 ...

  8. Android 再按一次退出应用的代码

    private long exitTime = 0; @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (key ...

  9. Decorator [ˈdekəreɪtə(r)] 修饰器/装饰器 -- 装饰模式

    装饰模式 -- 原先没有,后期添加的属性和方法 修饰器(Decorator)是一个函数,用来修饰类的行为.这是ES7的一个提案,目前Babel转码器已经支持. 需要先安装一个插件: npm insta ...

  10. [Android exception] /data/app/com.tongyan.tutelage-1/lib/arm/libstlport_shared.so: has text relocations

    java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/com.tongyan.tutelage-1/lib/arm/libstlport_s ...