Android布局分为五大类:相对布局、线性布局、表格布局、帧布局、网格布局

相对布局

语法格式:

<RelativeLayout

  xmlns:android="http://schemas.android.com/apk/res/android"

  xmls:tools=""http://schemas.android.com/tools

  android:layout_width=" "

  android:layout_height=" ">

  <Widgets>

    android:id="@+id/ "

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_centerHorizontal=" "

    android:layout_alignParentLeft=" "

    android:layout_marginLeft=" "

  </Widgets>

</RelativeLayout>

相对父容器布局的语法属性

  属性名称                                     属性说明

  layout_alignParentLeft                以父容器的左边缘为参照标准

layout_marginLeft                      控件左边缘距离父容器左边缘的距离

  layout_alignParentRigth              以父容器的有边缘为参照标准

  layout_marginRight                    控件右边缘距离父容器右边缘的距离

  layout_alignParentTop       以父容器的上边缘为参照标准

  layout_marginTop        控件上边缘距离父容器上边缘的距离

  layout_alignParentBottom      以父容器下边缘为参照标准

  layout_marginBottom      控件下边缘距离父容器下边缘的距离

layout_centerHorizontal      控件在父容器中水平居中

layout_centerHorizontal      控件在父容器中垂直居中

  layout_centerInParent       控件在父容器中央

例子:

  1. <?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">
  2.  
  3. <Button
    android:id="@+id/btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
  4.  
  5. android:layout_alignParentTop="true"
    android:layout_marginTop="128dp"
    android:layout_centerHorizontal="true"
    android:text="button1" />
  6.  
  7. </RelativeLayout>
  8.  

  1.  
  2. 相对控件布局的语法属性
      属性名称         属性说明
      layout_alignLeft      以已知控件的左边缘为参照标准
      layout_marginLeft      控件的左边缘与已知控件之间的距离
      layout_alignRight     以已知控件的右边缘为参照标准
      layout_marginRight 控件的右边缘与已知控件之间的距离
      layout_alignTop 以已知控件的上边缘为参考标准
    layout_marginTop     控件的上边缘与已知控件之间的距离
      layout_alignBottom     以已知控件的下边缘为参考标准
      layout_marginBottom    控件的下边缘与已知控件之间的距离
      layout_alignBaseLine    以已知控件的BaseLine为参考标准
  3.  
  4.   layout_toRightOf      控件位于已知控件的右侧
      layout_toLeftOf       控件位于已知控件的左侧
      layout_above       控件位于已知控件的上侧
    layout_below        控件位于已知控件的下侧
  5.  
  6. 例子
  1. <?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">
  2.  
  3. <Button
    android:id="@+id/btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
  4.  
  5. android:layout_centerInParent="true"
    android:text="button1"/>
  6.  
  7. <Button
    android:id="@+id/btn2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
  8.  
  9. android:layout_alignBottom="@+id/btn1"
    android:layout_marginBottom="85dp"
  1. android:layout_toRightOf="@+id/btn1"
    android:text="button2"/>
  2. </RelativeLayout>

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

  1. Android菜鸟成长记7 -- Android的五大布局

    Android五大布局,相信android的都了解过,今天我根据自己的学习整理一下五大布局,主要介绍的是线性布局(LiearLayout),因为,其他的布局使用率不是很高. Android的五大布局 ...

  2. 无废话Android之常见adb指令、电话拨号器、点击事件的4种写法、短信发送器、Android 中各种布局(1)

    1.Android是什么 手机设备的软件栈,包括一个完整的操作系统.中间件.关键的应用程序,底层是linux内核,安全管理.内存管理.进程管理.电源管理.硬件驱动 2.Dalvik VM 和 JVM ...

  3. Android first---常见布局

    ###绝对布局AbsoluteLayout    * android:layout_x="120dp"   在水平方向上偏移120像素     * android:layout_y ...

  4. 14.Android之Layout布局学习

    Android布局主要有5种,接下来学习总结下. 1) 最常见的线性布局 LinearLayout 线性布局是Android布局中最简单的布局,也是最常用,最实用的布局. android:orient ...

  5. Android中的布局优化方法

    http://blog.csdn.net/rwecho/article/details/8951009 Android开发中的布局很重要吗?那是当然.一切的显示样式都是由这个布局决定的,你说能不重要吗 ...

  6. [置顶] Android系统五大布局详解Layout

    我们知道Android系统应用程序一般是由多个Activity组成,而这些Activity以视图的形式展现在我们面前,视图都是由一个一个的组件构成的.组件就是我们常见的Button.TextEdit等 ...

  7. 个人经验 - Android的RelativeLayout布局的layout_height属性设置为wrap_content时的坑

    Android的RelativeLayout布局的layout_height属性设置为wrap_content时的坑: 此坑出现的条件: 1.RelativeLayout布局的layout_heigh ...

  8. Android学习5—布局简介

    Android界面的布局主要有四种,分别为RelativeLayout.LinearLayout.TableLayout.FrameLayout,接下来分别介绍这些布局如何使用(为了简单起见,接下来的 ...

  9. 【Android 复习】:Android五种布局的使用方法

    ---恢复内容开始--- 在Android布局中,有五种常用的布局,下面我们就来学习一下这几种布局的使用方式 1) 线性布局:LinearLayout 2) 帧布局:  FrameLayout 3)  ...

  10. Android学习----五大布局

    1.LinearLayout 线性布局 android:orientation="horizontal" 制定线性布局的排列方式 水平 horizontal 垂直 vertical ...

随机推荐

  1. SQL中SUBSTRING函数的用法

    功能:返回字符.二进制.文本或图像表达式的一部分 语法:SUBSTRING ( expression, start, length ) SQL 中的 substring 函数是用来抓出一个栏位资料中的 ...

  2. VB6.0调用DLL

    目录 第1章 VB6.0调用DLL    1 1 VC++编写DLL    1 1.1 使用__stdcall    1 1.2 使用 .DEF 文件    1 2 简单数据类型    2 2.1 传 ...

  3. SQL Server 2012清除连接过的服务器名称历史

    退出客户端后 SQL Server 2012: 删除这两个地方!请提前备份! X:\Users\XXX\AppData\Roaming\Microsoft\SQL Server Management ...

  4. GoF--原型设计模式

    用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象.

  5. inline-block的简单理解

    1. 概念display:inline-block 将对象呈现为inline对象,但是对象的内容作为block对象呈现.之后的内联对象会被排列在同一行内.比如我们可以给一个link(a元素)inlin ...

  6. hdu------2488Tornado(几何)

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

  7. uva----11729 Commando war (突击战争)

    G Commando War Input: Standard Input Output: Standard Output “Waiting for orders we held in the wood ...

  8. MVC 与传统的 webform 的比较

    代码架构方式 ASP 脚本语言和代码同置,每个请求页面对应一个物理文件 WebForm 代码后置 ,每个请求页面对应dll和一个.asp物理文件 MVC 代码分离,每个请求对应一个Action和一个V ...

  9. 5月23日 JavaScript

    一.JavaScript简介 1.JavaScript是什么: 它是个脚本语言,需要有宿主文件,它的宿主文件是HTML文件. 2.它的用法: 在HTML中位置有三块: (1)head里面 (2)bod ...

  10. 3D旋转动画

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    < ...