相對於父框架

  • 屬性值為true為對齊該方式,false為不對齊。

相對於父框架之方向

  • android:layout_alignParentTop

    對齊父框架之上方。

  • android:layout_alignParentBottom

    對齊父框架之下方。

  • android:layout_alignParentLeft

    對齊父框架之左方。

  • android:layout_alignParentRight

    對齊父框架之右方。

範例:對齊於父框架之右下方

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:text="Button 1" />

</RelativeLayout>

於父框架之置中

  • android:layout_centerHorizontal

    水平置中

  • android:layout_centerVertical

    垂直置中

  • android:layout_centerInParent

    水平、垂直皆置中

範例:於父框架中水平、垂直皆置中

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Button 1" />

</RelativeLayout>

相對於子元件或子框架

放置於子元件或子框架的特定方向

  • android:layout_above

    在被對齊元件的上方

  • android:layout_below

    在被對齊元件的下方

  • android:layout_toLeftOf

    在被對齊元件的左方

  • android:layout_toRightOf

    在被對齊元件的右方

對齊子元件或子框架的邊線

  • android:layout_alignTop

    對齊被對齊元件的上邊線

  • android:layout_alignBottom

    對齊被對齊元件的下邊線

  • android:layout_alignLeft

    對齊被對齊元件的左邊線

  • android:layout_alignRight

    對齊被對齊元件的右邊線

範例:在被對齊元件的上方並對齊其右邊線

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/center_button"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_centerInParent="true"
        android:text="Button 1" />

    <Button
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_above="@id/center_button"
        android:layout_alignRight="@id/center_button"
        android:text="Button 2" />

</RelativeLayout>

範例:在被對齊元件的左方並對齊其下邊線

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/center_button"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_centerInParent="true"
        android:text="Button 1" />

    <Button
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_toLeftOf="@id/center_button"
        android:layout_alignBottom="@id/center_button"
        android:text="Button 2" />

</RelativeLayout>