Friday, October 1, 2010

Position two buttons on each side of the screen

Working with layouts in Android can sometimes be extremely simple and other times extremely difficult to accomplish seemingly simple tasks. I fought for a while with how to position two buttons on each side of the screen with a space between them. I'll spare all of my trials and tribulations, and get right to the code that makes it work...

The trick is to use a RelativeLayout and implement the following button layout properties:
  • android:layout_alignParentLeft="true"
  • android:layout_alignParentRight="true"
<?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"
 android:orientation="horizontal"
 android:background="@color/white" >

 <Button
  android:id="@+id/back_btn"
  android:layout_width="100px"
  android:layout_height="wrap_content"
  android:text="Prev"
  android:layout_alignParentLeft="true"
  android:padding="10dip"
  android:background="@drawable/button"
  android:textColor="@color/white" />

 <Button
  android:id="@+id/forward_btn"
  android:layout_width="100px"
  android:layout_height="wrap_content"
  android:text="Next"
  android:layout_alignParentRight="true"
  android:background="@drawable/button"
  android:textColor="@color/white"
  android:padding="10dip" />

</RelativeLayout>

1 comment:

  1. Casino Hotel in Las Vegas, NV - Mapyro
    Casino Hotel in Las Vegas, NV - 영주 출장마사지 Use this simple 부산광역 출장샵 form 파주 출장마사지 to find casinos, motels, and other lodging 여주 출장마사지 near Casino Hotel in Las Vegas, NV. 춘천 출장안마

    ReplyDelete