I am trying to get 3 buttons aligned (left, center, right). I know that it can probably be done with gravity but I wam trying to understand the layout_weight concept here. I am using this code:
<LinearLayout
id=..
layout_width = "wrap_content"
layout_height = "wrap_content"
orientation="Horizonta"
>
<Button
id=1
layout_width = "wrap_content"
layout_height = "wrap_content"
layout_weight = "1"
text= "text" />
<Button
id=2
layout_width = "wrap_content"
layout_height = "wrap_content"
layout_weight = "1"
text= "text" />
<Button
id=3
layout_width = "wrap_content"
layout_height = "wrap_content"
layout_weight = "1"
text= "text" />
</LinearLayout>
However, I am getting the TOP portion of the image below. Which is correct. The question is why is button stretched to cover all the area it is allocated while I am using wrap_content?How can make it like the BOTTOM image?

Thank you
The layout_weight is used to indicate how the extra free space on the screen should be divided up among the widgets. In this case we have three buttons with the same layout_weight and hence so will the buttons grow equally much until all the free space is gone.
Must try something else to get original size buttons and the alignment that what we want (left – center – right). One problem is that the horizontal LinearLayout is not completely collaborative when it comes to respecting layout_gravity parameters. We will be able to use layout_gravity parameters that affect vertical alignment but horizontal are ignored by the parent LinearLayout, sigh another dead end.
A solution is to put something in between the button’s that pushes the them into right place in the screen. The Space view was introduced in API 14 (Ice Cream Sandwich) and is suitable to be used for this.
The Space views can also be replaced with a couple of empty TextViews to get the design to work on devices that run earlier API-levels.