Home  > Resources  > Blog

Making Equal Width Buttons in Android

 
September 27, 2010 by Bibhas Bhattacharya
Category: Mobile Computing

It is a common requirement to layout a bunch of buttons side by side. Making them of equal width is just plain good GUI design.

image

To achieve the effect above, first create a LinearLayout just for the buttons. The layout will contain three buttons.

<LinearLayout android_id="@+id/LinearLayout02" android_layout_height="wrap_content" 
  android_layout_width="fill_parent">
  <Button android_layout_height="wrap_content" android_text="Update" 
    android_layout_width="fill_parent" android_layout_weight="1"/>
  <Button android_layout_height="wrap_content" android_text="New" 
    android_layout_width="fill_parent" android_layout_weight="1"/>
  <Button android_layout_height="wrap_content" android_text="Delete" 
    android_layout_width="fill_parent" android_layout_weight="1"/>
</LinearLayout>

We took these steps to get the effect:

1. For the LinearLayout we set android_layout_width="fill_parent". This causes the layout view to take up the full width available from the device.

2. For each Button, we set android_layout_width="fill_parent" and android_layout_weight="1".

Follow Us

Blog Categories