一、相对于父容器

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.同方向对齐方式--><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮一"android:layout_centerInParent="true"/><!--位于父容器居中位置--><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮二"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"/><!--与父容器底端对齐--><!--位于父容器水平居中位置--><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮三"android:layout_alignParentRight="true"android:layout_centerVertical="true"/><!--与父容器右侧对齐--><!--位于父容器垂直居中位置--><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮四"android:layout_alignParentLeft="true"android:layout_centerVertical="true"/><!--与父容器左侧对齐--><!--位于父容器垂直居中位置--><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮五"android:layout_alignParentTop="true"android:layout_centerHorizontal="true"/><!--与父容器顶端对齐--><!--位于父容器水平居中位置--><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮六"/><!--与父容器左侧对齐--><!--与父容器顶端对齐--><!--默认位置--><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮七"android:layout_alignParentRight="true"/><!--与父容器右侧对齐--><!--与父容器顶端对齐--><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮八"android:layout_alignParentLeft="true"android:layout_alignParentBottom="true"/><!--与父容器左侧对齐--><!--与父容器底端对齐--><Buttonandroid: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   内间距--><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮一"android:layout_centerInParent="true"android:id="@+id/bt"/><!--父容器内居中--><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮二"android:layout_alignTop="@id/bt"android:layout_toLeftOf="@id/bt"/>//相对于按钮一  顶部对齐  位于左侧<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮三"android:layout_alignRight="@id/bt"android:layout_above="@id/bt"/>//相对于按钮一  右侧对齐  位于上方<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮四"android:layout_alignRight="@id/bt"android:layout_below="@id/bt"/>//相对于按钮一  右侧对齐  位于下方<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮五"android:layout_alignTop="@id/bt"android:layout_toRightOf="@id/bt"/>//相对于按钮一  顶部对齐  位于右侧<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮六"android:layout_toRightOf="@id/bt"android:layout_below="@id/bt"/>//相对于按钮一  位于右侧  位于下方<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮七"android:layout_toRightOf="@id/bt"android:layout_above="@id/bt"/>//相对于按钮一  位于右侧  位于上方<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮八"android:layout_toLeftOf="@id/bt"android:layout_above="@id/bt"/>//相对于按钮一  位于左侧  位于上方<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮九"android:layout_toLeftOf="@id/bt"android:layout_below="@id/bt"/>//相对于按钮一  位于左侧  位于下方<EditTextandroid: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<Buttonandroid: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按钮  位于父窗口右侧  输入框下方<Buttonandroid: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>

转载于:https://www.cnblogs.com/Chenshuai7/p/5321696.html

Android——RelativeLayout(相对布局)相关推荐

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

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

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

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

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

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

  4. Android 应用开发(37)---RelativeLayout(相对布局)

    RelativeLayout(相对布局) 在上一节中我们对LinearLayout进行了详细的解析,LinearLayout也是我们 用的比较多的一个布局,我们更多的时候更钟情于他的weight(权重 ...

  5. Android RelativeLayout布局

    1. RelativeLayout类 相对布局(RelativeLayout)将子视图以相对位置显示.默认显示在父视图的左上角. layout_alignParentTop,父视图的上边 layout ...

  6. 【Android】相对布局(RelativeLayout)最全解析

    [Android]相对布局(RelativeLayout)最全解析 一.相对布局(RelativeLayout)概述 二.根据父容器定位 三.根据兄弟控件定位 一.相对布局(RelativeLayou ...

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

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

  8. android 继承relativelayout,Android开发中RelativeLayout相对布局

    Android开发中RelativeLayout相对布局 RelativeLayout布局是Android界面布局中应用最广也最强大的一种布局,其不只十分灵活,能够解决开发中各类界面布局需求,同时也很 ...

  9. android relativelayout 点击事件,Android Relativelayout点击背景行为

    所以我有一个RecyclerView,它是由我的自定义布局(代码如下)填充.我制作了一个可绘制的背景,并将其设置在我的自定义布局的根部,以便用户单击该项目时,背景颜色会发生变化.每个项目的布局上还有一 ...

最新文章

  1. Spring boot -mongodb
  2. Qt工作笔记-通过信号与槽实现定时器
  3. BZOJ 1191 [HNOI2006]超级英雄Hero
  4. html5-svg和Two.js的使用方法(附案例)
  5. iPhoneXI/XI MAX机模曝光:浴霸式摄像头着实抢眼
  6. 将您的SQL Server工作负载迁移到PostgreSQL –第3部分
  7. ArcGIS GP应用-GP模型服务发布
  8. 退休后你和原工作单位还有联系吗?
  9. [转载] java调用c++的dll及java.lang.UnsatisfiedLinkError解决方法
  10. spring aop的简单使用
  11. 单线多拨的原理+穿透
  12. 连接到系统上的设备没有发挥作用解决方案
  13. AVPlayer就可以播放在线音频
  14. PCB EMC设计中的一些基本原则
  15. 《中台产品经理宝典》读后感11:大白话说透时下备受追捧的数字化转型是什么?
  16. php实现url伪静态化
  17. VS工程引用出现感叹号
  18. 每周分享第 21 期
  19. 2021建筑施工电工(建筑特种作业)机考题库及建筑电工模拟试题
  20. 读书寄语:泥泞的路上才有脚印

热门文章

  1. position based dynamics
  2. 高光谱和图像特征相融合的生菜病害识别
  3. oracle列传行函数,oracle行转列和列转行(pivot 和 unpivot 函数,wm_concat函数 )
  4. 人身三流指什么_保险合同的主体是什么,主体的变更是什么?
  5. 2d游戏地图编辑器_C语言实现大型2D格斗游戏,1.8万行代码!
  6. OpenCV-Python图像处理教程(源码及素材)
  7. java js对象转字符串数组_js 转json格式的字符串为对象或数组(前后台)的方法
  8. python 数组排序索引_python对数组进行排序,并输出排序后对应的索引值方式
  9. loss函数之SoftMarginLoss
  10. [每日一题] OCP1z0-047 :2013-07-12 多表插入