1.简介

relativeLayout为相对布局,它是新版本安卓的默认布局方式。相对布局可以设置一个部件相对于其他部件所在的位置,包括上下左右等等。

2.构建

android:layout_marginStart="XXdp":距离开始位置xxdp

android:layout_marginEnd="XXdp":距离结束位置xxdp

android:layout_marginTop="XXdp":距离某元素上边缘位置xxdp

android:layout_alignBottom="@+id/ID":该元素的下边缘和某元素下边缘对齐

android:layout_alignStart="@+id/ID":该元素的左边缘和某元素的左边缘对齐

android:layout_alignEnd="@+id/ID":该元素的右边缘和某元素右边缘对齐

android:layout_below="@+id/ID":该元素位于某元素的下方

android:layout_centerHorizontal="true":该元素水平居中

android:layout_alignParentTop="true":该元素贴紧父元素的上边缘

android:layout_alignParentStart="true":该元素贴紧父元素的左边缘

android:layout_alignParentEnd="true":该元素贴紧父元素的右边缘
 
代码如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="example.relativelayout.Activity1" >

<Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="25dp"
        android:text="@string/bt1" />

<Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button1"
        android:layout_alignBottom="@+id/button1"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="25dp"
        android:text="@string/bt2" />

<Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="82dp"
        android:text="@string/bt3" />

<Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/button1"
        android:layout_below="@+id/button3"
        android:layout_marginTop="90dp"
        android:text="@string/bt4" />

<Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/button4"
        android:layout_alignStart="@+id/button2"
        android:text="@string/bt5" />

</RelativeLayout>

3.展示

---恢复内容结束---

Android开发--RelativeLayout的应用的更多相关文章

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

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

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

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

  3. Android开发——LinearLayout和RelativeLayout的性能对比

    0. 前言 我们都知道新建一个Android项目自动生成的Xml布局文件的根节点默认是RelativeLayout,这不是IDE默认设置,而是由android-sdk\tools\templates\ ...

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

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

  5. Android开发之基本控件和详解四种布局方式

    Android中的控件的使用方式和iOS中控件的使用方式基本相同,都是事件驱动.给控件添加事件也有接口回调和委托代理的方式.今天这篇博客就总结一下Android中常用的基本控件以及布局方式.说到布局方 ...

  6. (转) Android开发性能优化简介

    作者:贺小令 随着技术的发展,智能手机硬件配置越来越高,可是它和现在的PC相比,其运算能力,续航能力,存储空间等都还是受到很大的限制,同时用户对手机的体验要求远远高于PC的桌面应用程序.以上理由,足以 ...

  7. Android开发-之五大布局

    在html中大家都知道布局是什么意思了,简单来说就是将页面划分模块,比如html中的div.table等.那么Android中也是这样的.Android五大布局让界面更加美化,开发起来也更加方便.当然 ...

  8. Android开发1:基本UI界面设计——布局和组件

    前言 啦啦啦~本学期要开始学习Android开发啦~ 博主在开始学习前是完完全全的小白,只有在平时完成老师要求的实验的过程中一步一步学习~从此篇博文起,博主将开始发布Android开发有关的博文,希望 ...

  9. Android开发自学笔记(Android Studio)—4.1布局组件

    一.引言 Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面.在Android4.0之前,我们通常说 ...

随机推荐

  1. Python 函数式编程 & Python中的高阶函数map reduce filter 和sorted

    1. 函数式编程 1)概念 函数式编程是一种编程模型,他将计算机运算看做是数学中函数的计算,并且避免了状态以及变量的概念.wiki 我们知道,对象是面向对象的第一型,那么函数式编程也是一样,函数是函数 ...

  2. 分享大家一个背景为下雪的JQuery

    <html><head> <meta charset="utf-8"> <meta content="IE=edge,chrom ...

  3. ESB 中的流量控制

    ESB 中的流量控制

  4. css布局之左侧固定右侧自适应布局

    参考代码如下: <form id="form1" style="height:100%; overflow:hidden;"> <div st ...

  5. JS中Float类型加减乘除 修复

    MXS&Vincene  ─╄OvЁ  &0000027─╄OvЁ  MXS&Vincene MXS&Vincene  ─╄OvЁ:今天很残酷,明天更残酷,后天很美好, ...

  6. struts_表单得到数据

    在大家学习struts表达式语言的时候经常会遇到,从表单的提交上面得到数据, 而如何将表单的数据得到呢? 下面就介绍其中的一种方式: :以类的方式进行注入我们以login为例子 首先可以在struts ...

  7. 【Python】我的Python学习笔记【1】【using Python 2】

    1.模块格式 #!/usr/bin/env python # -*- coding: utf-8 -*- ... ...def main(): ...... ... if __name__=='__m ...

  8. linux centos 6.5 运行MySQL Workbench 6.0找不到 libmysqlclient.so.16和libmysqlclient_r.so.16

    找到已安装mysql/lib目录下有类似文件: -rw-r--r-- root root 12月 : libmysqlclient.a lrwxrwxrwx root root 12月 : libmy ...

  9. lambda的使用ret = filter(lambda x : x > 22 ,[11,22,33,44])

    #!/usr/bin/env python #def f1(x) : # return x > 22 ret = filter(lambda x : x > 22 ,[11,22,33,4 ...

  10. CentOS7 续

    网络环境 第一步:通过cmd查询自己本机的IP,然后记录下来,手工配置到本地连接上面IP:子网掩码:DNS1:101.7.8.9DNS2:202.38.184.13 第二步:给物理机 本地连接配置第二 ...