Linear Layout and weight in Android

后端 未结 18 2761
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 02:41

I always read about this funny weight value in the Android documentations. Now I want to try it for the first time but it isn\'t working at all.

As I understand it

18条回答
  •  醉梦人生
    2020-11-22 02:56

    In the width field of button, replace wrap-content with 0dp.
    Use layout_weight attribute of a view.

    android:layout_width="0dp"  
    

    This is how your code will look like:

    
    
     

    layout_weight is used to distribute the whatever left space into proportions. In this case, the two buttons are taking "0dp" width. So, the remaining space will be divided into 1:1 proportion among them, i.e. the space will be divided equally between the Button Views.

提交回复
热议问题