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" 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".
First result from Google and just what I was looking for. It works. Thanks.
Saved me so much time! Thanks.
Thanks for the post. I also wrote an EqualSpaceLayout that is similar to the LinearLayout, but it will not distort the sizes of its child views. This is useful when you have custom image backgrounds. Check it out: http://www.dev-smart.com/archives/225
Thanks a lot. Helped.
thank you
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
Thanks a lot! hours of work finding this.
it was ood thanks alot