一、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. ASp.net 注册

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs ...

  2. Java中的ClassLoader

      Java中类的加载过程(如Dog类):   通过类型信息定位Dog.class文件. 载入Dog.class文件,创建相应的Class对象. 执行父类的静态字段定义时初始化语句和父类的静态初始化块 ...

  3. AreYouBusy

    AreYouBusy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...

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

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

  5. gcc/g++动态链接库和静态库的链接顺序

    转自:http://withc8212.blog.163.com/blog/static/11656983820109263562854/ so文件:动态库a文件: 静态库exe文件:可执行程序(li ...

  6. Linux下统计出现次数最多的指定字段值

    假设桌面上有一个叫“data.txt”的文本,内容如下: {id='xxx' info='xxx' kk='xxx' target='111111' dd='xxx'}{id='xxx' info=' ...

  7. response.setContentType()的参数说明

    response.setContentType()的参数说明 <meta http-equiv="Content-Type" content="text/html; ...

  8. MySQL中删除重复数据的简单方法,mysql删除重复数据

    MYSQL里有五百万数据,但大多是重复的,真实的就180万,于是想怎样把这些重复的数据搞出来,在网上找了一圈,好多是用NOT IN这样的代码,这样效率很低,自己琢磨组合了一下,找到一个高效的处理方式, ...

  9. 2016年11月1日 星期二 --出埃及记 Exodus 19:17

    2016年11月1日 星期二 --出埃及记 Exodus 19:17 Then Moses led the people out of the camp to meet with God, and t ...

  10. VC++ 禁止WebBrowser网页跳转时发出的声音和禁止网页上的文字被选择

    转载:http://blog.csdn.net/cometnet/article/details/51082091 #include <urlmon.h> #ifndef FEATURE_ ...