举例说明:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type here:"/>
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label"/>
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="OK" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
android:text="Cancel" />
</RelativeLayout>
首先:
    android:layout_below="@id/label"/>
表示当前控件放置于id为label 的控件下方。
    android:layout_alignParentRight="true"
表示当前控件的右端和父控件的右端对齐。属性值只能为true或false,默认false。
 android:layout_marginLeft="10dip"
表示使当前控件左边空出相应的空间。
    android:layout_toLeftOf="@id/ok"
表示使当前控件置于id为ok的控件的左边。
    android:layout_alignTop="@id/ok"
表示使当前控件与id控件的上端对齐。

相对布局主要有以下几种属性:


属性1:属性值为true或false
*android:layout_centerHrizontal
*android:layout_centerVertical
*android:layout_centerInparent
*android:layout_alignParentBottom
*android:layout_alignParentLeft
*android:layout_alignParentRight
*android:layout_alignParentTop
*android:layout_alignWithParentIfMissing
属性2:属性值必须为id的引用名“@id/id-name”
*android:layout_below
*android:layout_above
*android:layout_toLeftOf
*android:layout_toRightOf
*android:layout_alignTop
属性3:属性值为具体的像素值,单位为dip,px
*android:layout_marginBottom
*android:layout_marginLeft
*android:layout_marginRight
*android:layout_marginTop

xml范例:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<AnalogClock
android:id="@+id/aclock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
<DigitalClock
android:id="@+id/dclock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/aclock"
android:layout_alignLeft="@id/aclock"
android:layout_marginLeft="40px"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="当前时间:"
android:layout_toLeftOf="@id/dclock"
android:layout_alignTop="@id/aclock"/>
</RelativeLayout>
Tags:
Android RelativeLayout(相对布局)解析,Android相对布局范例,Android相对布局范例使用说明

更多相关文章

  1. listView 中relativeLayout 布局的 android:layout_alignParentB
  2. EditText 的常用属性与解释
  3. android 界面布局
  4. 51. (android开发)线性布局、相对布局、帧布局
  5. android:visibility属性
  6. 笔记 RelativeLayout:相对布局管理器:
  7. android Linearlayout中有关gravity与layout_gravity对布局的影
  8. android 控件xml属性
  9. Android 中的布局方式之线性布局

随机推荐

  1. 2011.07.20——— android 获得当前view
  2. Android(安卓)Framework 基础
  3. Android中的共享设置(SharedPreferences)
  4. Android开发UI之自定义控件的皮肤
  5. Android(安卓)建造者(Builder)模式
  6. Android:res之shape制作圆角、虚线、渐变
  7. MTK Android(安卓)Driver:PMIC
  8. android manifest.xml中元素含义
  9. android 读取sd卡中的图片
  10. Android(安卓): Android(安卓)Studio 3.4