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
|
1 answer
Your expectations are true. Try to remove weightSum, for it is not necessary in this case. Also set the height to 0dp
- one
WeightSumis not completely useless and allows you to set proportions when not all widgets in the container have weight. For example, if the root container hasweightSum = 2, and nestedlayout_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 heightwrap_content- pavlofff - @pavlofff, hmm ... did not know this) Corrected to "not necessary in this case") - Yuriy SPb ♦
|
layout_height="match_parent"withweight. This will lead to unpredictable consequences. Fully predict polslatsiya possible only withlayout_height="0dp"- Vladyslav Matviienko