Linear Layout and weight in Android

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

    3 things to remember:

    • set the android:layout_width of the children to "0dp"
    • set the android:weightSum of the parent (edit: as Jason Moore noticed, this attribute is optional, because by default it is set to the children's layout_weight sum)
    • set the android:layout_weight of each child proportionally (e.g. weightSum="5", three children: layout_weight="1", layout_weight="3", layout_weight="1")

    Example:

        
    
        

    And the result:

    Layout weight example

提交回复
热议问题