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       控件在父容器中央

例子:

<?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"> <Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:layout_marginTop="128dp"
android:layout_centerHorizontal="true"
android:text="button1" /> </RelativeLayout>


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

    bzoj1034:贪心 bzoj1036:树剖 bzoj1037:一个比较巧妙,利用连续性维护的dp. http://www.cnblogs.com/Sdchr/p/6129496.html bzoj ...

  2. 能源项目xml文件标签释义--<context:component-scan>

    <context:component-scan base-package="com.xindatai.ibs" use-default-filters="false ...

  3. IE和主流浏览器

    1.添加事件 addEventListener 主流 attachEvent     IE 2.移除事件 removeEventListener detachEvent 3.获取事件对象 event ...

  4. $.get的重写

    window.meng = window.meng || {}; (function () { function Get() { this.def = $.Deferred(); } Get.prot ...

  5. 企业用户选择Java多于.NET的 5个原因

    .NET 和 Java 是当今社会最受欢迎的两种编程语言, 长期的发展和强大的功能使他们足以在编程界立足. 十余年的争论也没得到结果的一个话题就是——他们哪个更好一些? 今天, 我们不再去讨论JAVA ...

  6. 《javascript高级程序设计》 第24章 最佳实践 Best Practices

    24.1 可维护性 Maintainability24.1.1 什么是可维护的代码 What Is Maintainable Code?24.1.2 代码约定 Code Conventions 24. ...

  7. linux下如何优雅的挂载一个外界设备(比如优盘)

    最近从事linux,实验室一个破服务器,能连上网,但是输入这样的命令:        yum -y install gcc yum -y install gcc-c++ ,居然说是没有这样的镜像,也罢 ...

  8. hdu----(4308)Saving Princess claire_(搜索)

    Saving Princess claire_ Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  9. python 循环设计

    for循环 1.range()用法 for循环后的in跟随一个序列的画,循环每次使用的序列元素而不是序列的下标 例:s='abcdefg' for i in range(0,len(s),3): pr ...

  10. ibatis基础

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE sqlMap PUBLIC "-/ ...