Mar 12, 2011

An example of RelativeLayout

An example of XML using RelativeLayout, two buttons are placed on both left and right, and the last button is placed on the center position.

An example of RelativeLayout

<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button
android:id="@+id/leftbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Left"
android:layout_alignParentLeft="true"
/>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/leftbutton"
>
<Button
android:id="@+id/rightbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Right"
android:layout_alignParentRight="true"
/>
<Button
android:id="@+id/centerbutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/rightbutton"
android:text="Center Button"
/>
</RelativeLayout>
</RelativeLayout>


3 comments:

  1. couldn't you put all 3 of the in 1 RLayout? why 2 of them>

    ReplyDelete
  2. This can also be done using one RLayout...

    ReplyDelete
  3. this can be made with only one RelativeLayout, using
    android:layout_centerHorizontal="true" in the middle one

    ReplyDelete

Infolinks In Text Ads