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. Canu Parameter Reference(canu参数介绍)

    链接:Canu Parameter Reference To get the most up-to-date options, run canu -options The default values ...

  2. SAP MM事务代码清单

  3. js用ajax和不同页面的php互相传值的方法

    js里的代码:<script> var json; //获取所有class名为zhi的标签 var zhi = document.getElementsByClassName('zhi') ...

  4. js实现页面跳转

    js方式的页面跳转1.window.location.href方式    <script language="javascript" type="text/java ...

  5. 31-View如何从Action取得数据

    从Action取得数据,在ASP.NET MVC可区分成两种方式,一种是“使用弱类型取得数据”,另一种则是“使用强类型取得数据”,两者的差别在于View页面最上方声明的方式. 如果View页面使用弱类 ...

  6. [saiku] 源码整合[普通WEB项目]

    saiku源码的整合分为[普通web项目整合]和[maven整合]两种 本节主要是讲解如何整合为普通的web项目 转载自:http://blog.csdn.net/gsying1474/article ...

  7. 在csdn里markdown感受

    先来一个百度百科   Markdown是一种可以使用普通文本编辑器编写的标记语言,通过简单的标记语法,它可以使普通文本内容具有一定的格式.   Markdown具有一系列衍生版本,用于扩展Markdo ...

  8. web基础之Structs(一篇)

           为什么有 struts 框架             Struct 的优点之处: 1.       struct的好处 2.       程序更加规范化 3.       程序的可读性提 ...

  9. IO流 总结二

    流只能操作数据. File 类 用来将文件或者文件夹封装成对象. 方便文件与文件夹进行操作 File对象可以作为参数传递给流的构造函数. 可以将已有的和已出现的文件或者文件夹封装成对象 File a ...

  10. maven搭建java ee项目

    1.点击File->New->Other,选择maven project   2.选择maven project,点击Next,,而后再点击next,进入如下界面 如图选择最后一个,点击n ...