Linear Layout and weight in Android

后端 未结 18 2900
伪装坚强ぢ
伪装坚强ぢ 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:58

    Below are the changes (Marked in BOLD) in your code:

    
    
         

    Since your LinearLayout has orientation as horizontal, therefore you will need to keep your width only as 0dp. for using weights in that direction . (If your orientation was vertical, you would have kept your height only 0dp).

    Since there are 2 views and you have placed android:layout_weight="1" for both the views, it means it will divide the two views equally in horizontal direction (or by width).

提交回复
热议问题