<?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.相对与和自己平级的控件 </RelativeLayout> 虽然相对布局需要对没有控件设置ID,才能使用,看起来LinearLayout方便写,实际上RelativeLayout更加对灵活,因为线性布局设置垂直或者水平就整版都是垂直与水平的,相对布局控制更加灵活写 相对布局,如果不指定ID,默认都是在左上角


相对bt_444控件中间线对齐:
android:layout_alignBaseline="@id/bt_333"

相对bt_444控件顶部对齐:

android:layout_alignTop="@id/bt_333"

相对bt_444控件的底部对齐:

android:layout_alignBottom="@id/bt_333"

<!--
    相对于父控件系列: 相对于父控件垂直居中
android:layout_centerVertical="true" 相对于父控件水平居中
android:layout_centerHorizontal="true" 相对于父控件正中间
android:layout_centerInParent="true" 相对于父控件的右边
android:layout_alignParentRight="true" 相对于父控件的左边
android:layout_alignParentLeft="true" 相对于父控件的顶部
android:layout_alignParentTop="true" 相对于父控件的底部
android:layout_alignParentBottom="true" 相对于父控件的结束(通常情况下是在父控件最右边)
android:layout_alignParentEnd="true" 相对于父控件的开始 最左边 相对布局的默认
android:layout_alignParentStart="true" 相对于平级控件系列: 相对于bt_111控件的底部
android:layout_below="@+id/bt_111" 相对于bt_111控件的顶部
android:layout_above="@id/bt_111" 相对于bt_111控件的右边
android:layout_toRightOf="@id/bt_111" 相对于bt_111控件的左边
android:layout_toRightOf="@id/bt_111" 相对与控件的中间对齐
android:layout_alignBaseline="@id/bt_333" 相对与控件的顶部对齐
android:layout_alignTop="@id/bt_333" 相对与控件的底部对齐
android:layout_alignBottom="@id/bt_333" 相对与控件的中间对齐
android:layout_alignBaseline="@id/bt_333" 相对与控件的左对齐
android:layout_alignLife="@id/bt_333" 相对与控件的右对齐
android:layout_alignRight="@id/bt_333" // 外边距 上下左右 一般情况下用于 View
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginBottom="20dp"
android:layout_marginRight="20dp"
android:layout_margin="20dp" 外边距往水平方向80dp
android:layout_marginHorizontal="80dp" 外边距往垂直方向80dp
android:layout_marginVertical="80dp" // 内边距 上下左右 一般情况下用于 ViewGroup 用来管控View
android:padding="40dp"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:paddingTop="40dp"
android:paddingBottom="40dp" 内边距往水平方向60dp
android:paddingHorizontal="60dp" 内边距往垂直方向60dp
android:paddingVertical="60dp"
-->

相对布局测试的代码:

<?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"
android:orientation="vertical"> <Button
android:id="@+id/bt_111"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1111" android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true" /> <Button
android:id="@+id/bt_222"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2222"
android:layout_toLeftOf="@id/bt_111"
android:layout_centerInParent="true"
/> <Button
android:id="@+id/bt_333"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:text="333"
android:layout_marginLeft="130dp"
android:layout_marginTop="130dp"
android:background="#f00"
/> <Button
android:id="@+id/bt_444"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="444"
android:layout_toRightOf="@id/bt_333"
android:layout_alignBaseline="@id/bt_333"
android:background="@color/colorAccent"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="555"
android:layout_alignParentStart="true"
/> </RelativeLayout>

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

  1. Android相对布局(RelativeLayout)

    Android相对布局(RelativeLayout) 备注:这里的视图和元素是等同的概念. RelativeLayout是一个允许子视图相对于其他兄弟视图或是父视图显示的视图组(通过ID指定).每个 ...

  2. Android之布局RelativeLayout

    线性布局的weight属性在等比例分配时比较方便,但是对复杂的界面,嵌套多层LinearLayout布局会导致渲染变慢,占用更多系统资源:而使用RelativeLayout的话,可能仅仅需要一层就可以 ...

  3. android的布局-----RelativeLayout(相对布局)

    学习导图 注:父容器定位的属性值只能是Boolean ,兄弟组件定位的属性值只能是ID 典型案例(梅花) <?xml version="1.0" encoding=" ...

  4. Android UI -- 布局介绍(布局包括FrameLayout, LinearLayout, RelativeLayout, GridLayout)

    首先介绍常用布局类 FrameLayout 最简单的布局管理器. 这个布局管理类有几个特性: 添加组件默认在左上角的. 如果添加多个组件会叠加到一起,并且都在左上角.(可以通过一gravity属性改变 ...

  5. Android 自学之相对布局 RelativeLayout

    相对布局(RelativeLayout),相对布局容器内子组件的位置总是相对兄弟组件.父容器来决定的. RelativeLayout的XML属性及相关方法说明 XML属性 相关方法 说明 androi ...

  6. [Irving]Android 常用布局之RelativeLayout

    RelativeLayout相对布局 相对布局 RelativeLayout 允许子元素指定它们相对于其父元素或兄弟元素的位置,这是实际布局中最常用的布局方式之一. 它灵活性大很多,当然属性也多,操作 ...

  7. 一步一步学android之布局管理器——RelativeLayout

    今天开始学习RelativeLayout(相对布局),相对布局在平时布局的时候用的较多,因为Android适配方面的原因.相对布局可以控制组件摆放的位置(放在任一组件的上下左右等位置),下面来看看类的 ...

  8. Android 五大布局(LinearLayout、FrameLayout、AbsoulteLayout、RelativeLayout、TableLayout )

    前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net        ...

  9. android LinearLayout和RelativeLayout实现精确布局

    先明确几个概念的区别: padding margin:都是边距的含义,关键问题得明白是什么相对什么的边距padding:是控件的内容相对控件的边缘的边距. margin  :是控件边缘相对父空间的边距 ...

  10. .Net程序猿玩转Android开发---(7)相对布局RelativeLayout

                 相对布局RelativeLayout是Android布局中一个比較经常使用的控件,使用该控件能够布局出适合各种屏幕分辨率的布局,RelativeLayout採用相对位置进行 ...

随机推荐

  1. Tkinter Menubutton(菜单按钮)

    Python - Tkinter Menubutton: 一个菜单按钮是一个下拉菜单,在屏幕上停留时间的一部分.菜单的小工具,可以显示该菜单按钮的选择,当用户点击它与每个menubutton时.   ...

  2. 用Jmeter制造软件测试数据

    在测试过程难免会遇到一些需要大量测试数据的情况,如果数据没有太多的需求,或者需求本身比较简单,这时候我们可以用Jmeter参数化来实现(建议用badboy录制) 首先,我们可以通过badboy来录制实 ...

  3. 六、配置github的pull request触发jenkins自动构建

    之前的配置,都是向master分支push操作触发jenkins进行构建,但是在一般的正常工作中,不会允许程序员直接向主分支推送代码:正常都是fork一个本地的分支,在本地分支调试完后,向主干分支提交 ...

  4. dclcommon200.bpl

    xe6 dclcommon200.bpl xe7 dclcommon210.bpl xe8  dclcommon220.bpl xe7,xe8都有对应的文件,xe6为何没有?

  5. C语言清空输入缓冲区的N种方法对比(转)

    C语言中有几个基本输入函数: //获取字符系列 int fgetc(FILE *stream); int getc(FILE *stream); int getchar(void); //获取行系列 ...

  6. Spring3开发(一)

    1 Ioc是什么? Ioc:Inversion of Control,控制反转,控制权从应用程序转移到框架(如Ioc容器),是框架的共有特性. 1.1 为什么需要IoC容器?IoC容器是如何演变的? ...

  7. Node.js版-七夕无事,人艰勿拆,求别说...

    七夕无事,端坐电脑前coding,略苦逼,人艰勿拆,求别说...

  8. spring的传播行为和隔离级别

    7个传播行为,4个隔离级别(转自 http://www.blogjava.net/freeman1984/archive/2010/04/28/319595.html) Spring事务的传播行为和隔 ...

  9. Linux实战教学笔记38:企业级Nginx Web服务优化实战(下)

    四,Nginx站点目录及文件URL访问控制 4.1 根据扩展名限制程序和文件访问 Web2.0时代,绝大多数网站都是以用户为中心多的,例如:bbs,blog,sns产品,这几个产品都有一个共同特点,就 ...

  10. ssh框架,工具类调用service层方法

    解决方法: @Component//声明为spring组件 public class CopyFileUtil{ @Autowired private DataFileManager dataFile ...