September 27, 2010 by

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.


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" 
  <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"/>

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".



Not the perfect ans as the buttons are still of different widths

instead use android:width=”_(your desired size)_dp”
but use linear layout, else it will not work

this is the working code

Comments are closed.