I have 3 views in vertical LineartLayout. I want to make width of each the same, bu开发者_运维百科t as small as the larger view can be.
Each view is a button, and have different text size. So if i set wrap_content, every button have different size. If i set fill_parent - every view is as large as screen.
So how can i do that without runtime code (only xml layout markup)?
Set all button's widths to fill_parent
with the layout_weight="1"
for each of them. Like
<Linearlayout ...>
<Button android:layout_width="fill_parent"
........
anddroid:layout_weight="1"/>
<Button android:layout_width="fill_parent"
........
anddroid:layout_weight="1"/>
<Button android:layout_width="fill_parent"
........
anddroid:layout_weight="1"/>
</LinearLayout>
Setting weights
Set the absolute dimensions for the layout width and height of the view Eg: android:layout_width="30dip" android:layout_height="15dip"
Set the style attributes for the buttons: A Button can have a few style attributes that can be set on it:
- normal button – no style attributes required, this is the default
- normal right style – style=”?android:attr/buttonStyleRight”
- small style – style=”?android:attr/buttonStyleSmall”
- small right style – style=”?android:attr/buttonStyleSmallRight”
Any of the above three things can be done to achieve the desired result.
精彩评论