开发者

Set view width as the latger view of group

开发者 https://www.devze.com 2023-04-02 19:57 出处:网络
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.

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> 


  1. Setting weights

  2. Set the absolute dimensions for the layout width and height of the view Eg: android:layout_width="30dip" android:layout_height="15dip"

  3. Set the style attributes for the buttons: A Button can have a few style attributes that can be set on it:

    1. normal button – no style attributes required, this is the default
    2. normal right style – style=”?android:attr/buttonStyleRight”
    3. small style – style=”?android:attr/buttonStyleSmall”
    4. small right style – style=”?android:attr/buttonStyleSmallRight”

Any of the above three things can be done to achieve the desired result.

0

精彩评论

暂无评论...
验证码 换一张
取 消