单个控件属性(2)
layout_toLeftOf(参考组件左方)
layout_toRightOf(参考组件右方)
layout_above(参考组件上方)
layout_below(参考组件下方)
layout_alignTop(对齐参考组件的上边界)
layout_alignBottom(对齐参考组件的下边界)
layout_alignLeft(对齐参考组件的左边界)
layout_alignRight(对齐参考组件的右边界)
- 只有一个属性(1)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="参考组件"
android:layout_centerInParent="true"
android:id="@+id/mainButton1"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="右方"
android:layout_toRightOf="@id/mainButton1"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="下方"
android:layout_below="@id/mainButton1"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="上方"
android:layout_above="@id/mainButton1"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="左方"
android:layout_toLeftOf="@id/mainButton1"/>
</RelativeLayout>
上效果
- 只有一个属性(2)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="参考组件"
android:layout_centerInParent="true"
android:id="@+id/mainButton1"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="右方"
android:layout_alignRight="@id/mainButton1"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="下方"
android:layout_alignBottom="@id/mainButton1"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="上方"
android:layout_alignTop="@id/mainButton1"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="左边"
android:layout_alignLeft="@id/mainButton1"/>
</RelativeLayout>
上图
图片中虽然看着只有两个,但是实际上却是左右两个重合在上方;上下两个重合在左方。