一、RelativeLayout(相对布局)概述

  RelativeLayout是相对布局控件,它包含的子控件将以控件之间的相对位置或者子类控件相对父类容器的位置的方式排列

二、RelativeLayout(相对布局)的属性

  1、子类控件在RelativeLayout中常用到的属性(相对于父容器的一个位置)

    android:layout_alignParentLeft = "true"  子类控件相对当前父类容器靠左边(默认)

    android:layout_alignParentTop = "true"  子类控件相对父容器靠上边

    android:layout_alignParentRight="true"    子类控件相对父容器靠右边
    android:layout_alignParentBottom="true"    子类控件相对父容器靠下边

    android:layout_margin="20dp"      子类控件距离父类容器四边的距离

    android:layout_marginLeft = "41dp"    子类控件距离父类容器左边的距离

    android:layout_marginTop = "41dp"    子类控件距离父类容器上边的距离

    android:layout_marginBottom = "41dp"    子类控件距离父类容器下边的距离

    android:layout_marginRight = "41dp"    子类控件距离父类容器右边边的距离

    android:layout_centerInParent = "true"   子类控件相对父容器即水平居中有垂直居中

    android:layout_centerHorizontal = "true"   子类控件相对父容器水平居中 

    android:layout_centerVertical = "true"    子类控件相对父容器垂直居中

  2、子类控件相对于子类控件的一个位置

    android:layout_below = "@+id/button1"    该控件位于给定id控件的底部

    android:layout_toRightOf = "@+id/button1"     该控件位于给定id控件的右边

    android:layout_above = "@+id/button1"     该控件位于给定id控件的上面

    android:layout_toLeftOf = "@+id/button1"     该控件位于给定id控件的左边

    android:layout_alignBaseline = "@+id/button1"    该控件的内容与给定id控件的内容在一条线上

    android:layout_alignBottom    该控件的底部边缘与给定id控件的底部边缘对齐

    android:layout_alignLeft    该控件的底部边缘与给定id控件的左部边缘对齐

    android:layout_alignRight    该控件的底部边缘与给定id控件的右部边缘对齐

    android:layout_alignTop    该控件的底部边缘与给定id控件的顶部边缘对齐

、RelativeLayout(相对布局)使用例子

    在商城中通常会有这样的布局,一个图片  右边有几条信息

     

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="26dp"
        android:layout_marginTop="26dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/imageView1"
        android:layout_marginLeft="24dp"
        android:layout_toRightOf="@+id/imageView1"
        android:text="狗不理包子" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:text="20元" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView1"
        android:layout_alignLeft="@+id/textView2"
        android:text="有贵又不好吃" />

</RelativeLayout>

Android布局_相对布局RelativeLayout的更多相关文章

  1. CSS3_伸缩盒模型_弹性布局_等分布局_flex 布局

    伸缩盒模型 CSS3 引入的布局模式 Flexbox 布局 主要思想: 让容器有能力让其子项目能够改变其宽度,高度,以最佳方式填充可用空间. 特点: display: flex;    只能控制其子元 ...

  2. Android布局_网格布局GirdLayout

    自Android4.0版本后新增的GirdLayout网格布局(API 14) <?xml version="1.0" encoding="utf-8"? ...

  3. Android布局_表格布局TableLayout

    一.TableLayout概述 TableLayout表格布局模型以行列的形式管理子控件,每一行为一个TableRow的对象,当然也可以是一个View的对象 二.TableLayout的全局属性  1 ...

  4. Android布局_帧布局FrameLayout

    一.FrameLayout布局概述 在这个布局中,所有的子元素都不能被指定放置的位置,他们统统放于这块区域的左上角,并且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素部分和全部遮挡  如下面的 ...

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

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

  6. Android 自学之相对布局 RelativeLayout

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

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

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

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

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

  9. [转]浅谈Android五大布局(二)——RelativeLayout和TableLayout

    在浅谈Android五大布局(一)中已经描述了LinearLayout(线性布局).FrameLayout(单帧布局)和AbsoulteLayout(绝对布局)三种布局结构,剩下的两种布局Relati ...

随机推荐

  1. Squares 分类: POJ 2015-08-04 11:46 3人阅读 评论(0) 收藏

    Squares Time Limit: 3500MS Memory Limit: 65536K Total Submissions: 17462 Accepted: 6634 Description ...

  2. 第十二届浙江省大学生程序设计大赛-Beauty of Array 分类: 比赛 2015-06-26 14:27 12人阅读 评论(0) 收藏

    Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. ...

  3. 浅谈算法和数据结构: 七 二叉查找树 八 平衡查找树之2-3树 九 平衡查找树之红黑树 十 平衡查找树之B树

    http://www.cnblogs.com/yangecnu/p/Introduce-Binary-Search-Tree.html 前文介绍了符号表的两种实现,无序链表和有序数组,无序链表在插入的 ...

  4. java中的动态代理机制

    java中的动态代理机制 在java的动态代理机制中,有两个重要的类或接口,一个是 InvocationHandler(Interface).另一个则是 Proxy(Class),这一个类和接口是实现 ...

  5. Spring资源访问

    资源访问 1.Resource Jdk提供的访问资源的类并不能很好地满足各种底层的资源访问需求, 比如缺少从类路径或者web容器的上下文中获取资源的操作类. 鉴于此, Spring设计了一个Resou ...

  6. 查看Mac电脑的开机记录

    回家以后,发现电脑前的地面上有烟灰.我记不住是不是我抽烟时掉的了.当然,如果不是我掉的,就是别人掉的了.要是别人掉的,估计是坐在我这玩儿电脑的时候掉的了.查一下开机记录吧.打开终端,输入“last|g ...

  7. 2016年10月29日 星期六 --出埃及记 Exodus 19:14

    2016年10月29日 星期六 --出埃及记 Exodus 19:14 After Moses had gone down the mountain to the people, he consecr ...

  8. Struts2的处理结果(二)——处理结果的类型

    Struts2的处理结果(二) --处理结果的类型 1.Struts2內建的支持的结果类型: 在<result>元素中的type属性,确定了结果类型. chain:Action链式处理的结 ...

  9. nohup不输出日志信息的方法,及linux重定向学习

    起因 最近使用nohup创建了一个后台进程,默认日志输出到了nohup.out文件中,程序跑起来也就没再管,过了大约一周,发现硬盘空间不够了,于是查找原因,发现这个nohup.out文件已经到了70G ...

  10. Some Useful Property Settings Explained Of Oracle Forms

    In Oracle forms when we have two or more blocks and there is a requirement to join them or make a re ...