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_above将该控件的底部置于给定ID的控件之上;

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

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

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

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

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

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

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

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


3属性值为具体的像素值,如30dip,40px
android:layout_marginBottom 距离指定元素底部的距离
android:layout_marginLeft 距离指定元素左边的距离
android:layout_marginRight 距离指定元素右边的距离
android:layout_marginTop 距离指定元素顶部的距离

举一个例子,main.xml文件及运行图如下, <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=" http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fr">
<TextView
android:layout_marginTop="10dip"
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name"
android:textSize="20dp" />
<EditText
android:id="@+id/fillname"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/textview1"
android:layout_alignBottom="@id/textview1"/>
<TextView
android:layout_marginTop="10dip"
android:id="@+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sex"
android:textSize="20dp"
android:layout_below="@id/textview1"/>
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_x="60px"
android:layout_y="6px"
android:layout_toRightOf="@id/textview2"
android:layout_alignTop="@id/textview2"
android:layout_alignBottom="@id/textview2">
<RadioButton
android:id="@+id/radiobutton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rb1"
android:layout_below="@id/fillname"
/>
<RadioButton
android:id="@+id/radiobutton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rb2"
/>
</RadioGroup>
<TextView
android:layout_marginTop="11dip"
android:id="@+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/aihao"
android:textSize="20dp"
android:layout_below="@id/textview2"/>
<CheckBox
android:id="@+id/cb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/aihao1"
android:layout_toRightOf="@id/textview3"
android:layout_alignTop="@id/textview3">
</CheckBox>
<CheckBox
android:id="@+id/cb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/aihao2"
android:layout_toRightOf="@id/cb1"
android:layout_alignTop="@id/cb1">
</CheckBox>
<CheckBox
android:layout_marginTop="2dip"
android:id="@+id/cb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/aihao3"
android:layout_below="@id/cb1"
android:layout_alignLeft="@id/cb1">
</CheckBox>
<CheckBox
android:id="@+id/cb4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/aihao4"
android:layout_toRightOf="@id/cb3"
android:layout_alignTop="@id/cb3">
</CheckBox>
<CheckBox
android:id="@+id/cb5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/aihao5"
android:layout_toRightOf="@id/cb4"
android:layout_alignTop="@id/cb4">
</CheckBox>
</RelativeLayout>
RelativeLayout 用法以及举例_第1张图片

更多相关文章

  1. Form表单组合控件
  2. Android控件笔记——CheckBox复选框
  3. Android 布局----让一个控件居底部
  4. Android中控件的隐藏和显示
  5. 各种控件
  6. 用EditText控件的属性inputType
  7. Android Studio控件属性大全

随机推荐

  1. Android NDK学习记录(一)
  2. android应用程序键盘事件机制
  3. 报错You need to use a Theme.AppCompat
  4. 【android初级】之android布局属性详解
  5. Android Layout属性详解
  6. 布局技巧和列表控件
  7. Android ScrollView滚动条
  8. android sdk的快速安装法
  9. Android基本控件TextView
  10. Android应用程序的debug属性