举例说明:

<?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. 51. (android开发)线性布局、相对布局、帧布局
  2. EditText 的常用属性与解释
  3. android:visibility属性
  4. Android之动画效果编程基础
  5. android XML下searchable.xml
  6. android Linearlayout中有关gravity与layout_gravity对布局的影
  7. android 控件xml属性
  8. Android(安卓)Fresco属性大全,中文说明
  9. Android(安卓)xml资源文件中@、@android:type、@*、?、@+含义和区

随机推荐

  1. android UDP广播、组播
  2. Android(安卓)NDK开发动态加载so示例源码
  3. Android中显示照片的Exif信息
  4. android启动过程
  5. Android(安卓)Studio 连接夜神模拟器
  6. Android--布局方式(LinearLayout)学习
  7. Unity3D导出为android程序invokation fai
  8. Android下USB框架
  9. [置顶] android IPC通信(下)-AIDL
  10. TextView的跑马灯效果,还有焦点问题