What is android:weightSum in android, and how does it work?

前端 未结 9 759
梦毁少年i
梦毁少年i 2020-11-22 04:02

I want to know: What is android:weightSum and layout weight, and how do they work?

9条回答
  •  一向
    一向 (楼主)
    2020-11-22 04:08

    The documentation says it best and includes an example, (highlighting mine).

    android:weightSum

    Defines the maximum weight sum. If unspecified, the sum is computed by adding the layout_weight of all of the children. This can be used for instance to give a single child 50% of the total available space by giving it a layout_weight of 0.5 and setting the weightSum to 1.0.

    So to correct superM's example, suppose you have a LinearLayout with horizontal orientation that contains two ImageViews and a TextView with. You define the TextView to have a fixed size, and you'd like the two ImageViews to take up the remaining space equally.

    To accomplish this, you would apply layout_weight 1 to each ImageView, none on the TextView, and a weightSum of 2.0 on the LinearLayout.

提交回复
热议问题