android:layout_height 50% of the screen size

前端 未结 10 907
无人共我
无人共我 2020-12-23 16:29

I just implemented a ListView inside a LinearLayout, but I need to define the height of the LinearLayout (it has to be 50% of the screen height).



        
10条回答
  •  自闭症患者
    2020-12-23 17:03

    To achieve this feat, define a outer linear layout with a weightSum={amount of weight to distribute}.

    it 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.Another example would be set weightSum=2, and if the two children set layout_weight=1 then each would get 50% of the available space.

    WeightSum is dependent on the amount of children in the parent layout.

提交回复
热议问题