There is a root tag LinearLayout with a vertical orientation, in which there are 3 children of the same LinearLayout . If in each of the children we put layout_weight="1" , layout_height="match_parent" , and in root weightSum="3" , then, as expected, the children occupy every 1/3 of the height. However, if we change the root weight, say 4, and on average of the children, put layout_weight="2" , then the second and third children creep somewhere off the screen, although I expected the average to take half the total height, and the top and lower - one fourth

  • one
    Do not use layout_height="match_parent" with weight . This will lead to unpredictable consequences. Fully predict polslatsiya possible only with layout_height="0dp" - Vladyslav Matviienko
  • one
    set the height of the nested container layout_height = "0dp". If all nested elements have a weight parameter, then weightSum is optional in the root - it will be calculated from nested elements - pavlofff
  • yes, with 0dp everything worked as it should, thanks)) - Pustota

1 answer 1

Your expectations are true. Try to remove weightSum, for it is not necessary in this case. Also set the height to 0dp

  • one
    WeightSum is not completely useless and allows you to set proportions when not all widgets in the container have weight. For example, if the root container has weightSum = 2 , and nested layout_weight = 1 , then the nested one will occupy 50% of the root, which is useful when a certain widget needs a certain ratio, and the rest that remains along their height wrap_content - pavlofff
  • @pavlofff, hmm ... did not know this) Corrected to "not necessary in this case") - Yuriy SPb