先来看一下相对布局的主要属性有哪些:

Android:layout_above 将该控件的底部置于给定ID的控件之上;

Android:layout_below 将该控件的底部置于给定ID的控件之下;

Android:layout_toLeftOf 将该控件的右边缘与给定ID的控件左边缘对齐;

Android:layout_toRightOf 将该控件的左边缘与给定ID的控件右边缘对齐;

-------------------------------------------------------------------------

Android:layout_alignParentTop 如果为true,将该控件的顶部与其父控件的顶部对齐;

Android:layout_alignParentBottom 如果为true,将该控件的底部与其父控件的底部对齐;

Android:layout_alignParentLeft 如果为true,将该控件的左部与其父控件的左部对齐;

Android:layout_alignParentRight 如果为true,将该控件的右部与其父控件的右部对齐;

----------------------------------------------------------------------------------

Android:layout_alignBaseline 将该控件的baseline与给定ID的baseline对齐;

Android:layout_alignTop 将该控件的顶部边缘与给定ID的顶部边缘对齐;

Android:layout_alignBottom 将该控件的底部边缘与给定ID的底部边缘对齐;

Android:layout_alignLeft 将该控件的左边缘与给定ID的左边缘对齐;

Android:layout_alignRight 将该控件的右边缘与给定ID的右边缘对齐;

-------------------------------------------------------------------------------

代码示例:

先看效果:

Android布局之RelativeLayout学习_第1张图片

Android布局之RelativeLayout学习_第2张图片

XML代码:

<?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"     >    <TextView         android:id="@+id/username"        android:textSize="16dp"        android:layout_height="wrap_content"        android:layout_width="fill_parent"        android:text="@string/username"        />    <EditText         android:id="@+id/input_user"        android:hint="@string/input_name"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_below="@+id/username"        />    <TextView         android:id="@+id/password"        android:textSize="16dp"        android:layout_height="wrap_content"        android:layout_width="fill_parent"        android:layout_below="@+id/input_user"        android:text="@string/password"        />    <EditText        android:id="@+id/input_pwd"        android:hint="@string/input_pwd"        android:inputType="textPassword"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_below="@+id/password"         />    <Button         android:text="@string/ok"        android:layout_height="wrap_content"        android:layout_width="wrap_content"        android:textSize="16dp"        android:id="@+id/ok"        android:layout_alignParentRight="true"        android:layout_below="@+id/input_pwd"        />    <Button        android:id="@+id/cancl"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@+id/input_pwd"        android:layout_toLeftOf="@+id/ok"        android:text="@string/cancl"        android:textSize="16dp" /></RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="fill_parent"    android:layout_height="fill_parent" >    <Button         android:id="@+id/button"        android:layout_height="wrap_content"        android:layout_width="wrap_content"        android:layout_centerInParent="true"        android:textSize="16dp"        android:text="@string/button"        />    <Button         android:id="@+id/button1"        android:layout_height="wrap_content"        android:layout_width="wrap_content"        android:textSize="16dp"        android:layout_toRightOf="@id/button"        android:layout_below="@id/button"        android:text="@string/button1"        />    <Button         android:id="@+id/button2"        android:layout_height="wrap_content"        android:layout_width="wrap_content"        android:textSize="16dp"        android:layout_below="@id/button"        android:layout_toLeftOf="@id/button"        android:text="@string/button2"        />    <Button         android:id="@+id/button3"        android:layout_height="wrap_content"        android:layout_width="wrap_content"        android:textSize="16dp"        android:layout_toRightOf="@id/button"        android:layout_above="@id/button"        android:text="@string/button3"        />    <Button         android:id="@+id/button4"        android:layout_height="wrap_content"        android:layout_width="wrap_content"        android:textSize="16dp"        android:layout_toLeftOf="@id/button"        android:layout_above="@id/button"        android:text="@string/button4"        />    </RelativeLayout>

工具:eclipse3.7+adt 20测试成功

更多相关文章

  1. Android六大基本布局详解
  2. Android对弹出输入法界面影响app界面布局
  3. Android常用控件之EditText
  4. android常用控件应用之文本框(TextView)特效
  5. Android EditText控件使用

随机推荐

  1. Android开发整理
  2. 在gradle中配置umeng多渠道以及不同的ume
  3. Android 获取View高度宽度
  4. WebViewJavascriptBridge实现js与android
  5. Android常用框架地址
  6. 45个android实例源码
  7. Android之NetworkOnMainThreadException
  8. android 可滑动的View
  9. Launcher开发笔记4—壁纸
  10. Android Studio基础之项目目录结构(四)-