Thursday, May 26, 2011

Android - Aligning Two Views Side-by-Side

This was harder than I thought it would be - I tried playing about with relative views plus alignment settings, table views, gravity and so on.

The answer turned out to be use a LinearLayout with orientation set to horizontal and for each view (buttons in my case) set width to fill parent and layout_weight to "1":


<LinearLayout
  android:id="@+id/Table01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_alignParentBottom="true">    
<Button
android:id="@+id/button1"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="15sp"
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="reset">
</Button>
<Button
android:id="@+id/button2"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="15sp"
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="delete">
</Button>
  </LinearLayout>

No comments:

Post a Comment