I am using layout_weight to specify the ratios of various views in a specific viewGroups in android.
From this question's answer I have got clear concept about what layout_weight is. I calculate the size of all viewsin a viewGroup using normal mathematics (i.e I have 3 views of 1,2 & 3 layout_weights & all of them have layout_height="0dp" then they have 1/(1+2+3), 2/(1+2+3), 3/(1+2+3) spaces in their viewGroup for Verical alignment).
But, what does layout_weight="0" mean? How can I determine the view's size having layout_weight="0"?
For all the view which have layout_weight must have layout_height or layout_width as 0dp depending on the orientation and requirement of layout.
layout_weight="1" and layout_width="0dp" ==> that particular view will be stretched horizontally if there is not other layout adjacent to it.
layout_weight="0" and layout_width="100dp" ==> that particular layout will behave as it is there is no meaning of layout_weight in this scenario.
Best use of weight is when you need two views having same height/width that are adjacent to each other you can add width/height as "0dp" for both layout and weight as "1" for both the layout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With