RelativeLayout布局 

在相对布局中,至少要确定组件的“左右“ “上下” 两个位置才能准确固定组件位置

组件之间的位置关系:

android:layout_above 

android:layout_above="@id/btn2"表示与id为btn2的组件的上边缘对齐

android:layout_below

android:layout_toLeftOf

android:layout_toRightOf

组件对齐方式:

android:layout_alignBaseline 将该组件放在指定id组件进行中心线对齐

android:layout_alignTop

android:layout_alignBottom

android:layout_alignLeft

android:layout_alignRight

当前组件与父组件的对齐方式:

android:layout_alignParentTop与父组件进行顶部对齐

android:layout_alignParentBottom

android:layout_alignParentLeft

android:layout_alignParentRight

组件放置位置:

android:layout_centerHorizontal放置在水平方向的中央位置

android:layout_centerVertical放置为垂直方向的中央位置

android:layout_centerInParent放置在父组件的水平中央及垂直中央的位置


以下代码示例:

    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=".MainActivity" >

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="Button1"

    android:id="@+id/btn1"

    />

   

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:text="Button2"

        android:id="@+id/btn2"

        android:layout_below="@id/btn1"

        />

   

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Button3"

        android:id="@+id/btn3"

        android:layout_below="@id/btn2"

        android:layout_alignParentRight="true"

        />

     

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:text="Button4"

         android:id="@+id/btn4"

         android:layout_below="@id/btn3"

         android:layout_alignParentRight="true"

         />

     

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:text="Button5"

         android:id="@+id/btn5"

         android:layout_below="@id/btn4"

         android:layout_centerHorizontal="true"

         />



更多相关文章

  1. Android学习——基础组件
  2. ScrollView属性fillViewport解决android布局不能撑满全屏的问题
  3. Android(安卓)SDK 2.0 安装
  4. Android音乐播放器简单示例
  5. [置顶] Android(安卓)通过经纬度获取地理位置信息
  6. Android(安卓)adb命令启动系统组件
  7. Android开发指南整理
  8. android GPS定位,定位城市称,经纬度
  9. Android(安卓)解决阿里云直播水印问题

随机推荐

  1. php如何使用PHPAnalysis提取关键字中文分
  2. 简单的php多线程解决方法
  3. 教你用PHP实现微信小程序人脸识别刷脸登
  4. 谈一谈php面向对象的理解
  5. php实现文件上传到服务器(含代码)
  6. 十大最主流的PHP框架
  7. 新手应该知道的php多图片上传的实现
  8. php构建一个区块链(含源码)
  9. PHP global 关键词的实例详解
  10. use在php中的使用方法(代码示例)