Assign width to half available screen width declaratively

前端 未结 5 2167
北恋
北恋 2020-11-28 23:43

Is it possible to assign a widget width to half the available screen width, and do it using declarative xml?

5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 00:06

    If your widget is a Button:

    
        

    I'm assuming you want your widget to take up one half, and another widget to take up the other half. The trick is using a LinearLayout, setting layout_width="fill_parent" on both widgets, and setting layout_weight to the same value on both widgets as well. If there are two widgets, both with the same weight, the LinearLayout will split the width between the two widgets.

提交回复
热议问题