Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android- meaning of layout_weight="0"

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"?

like image 752
Utshaw Avatar asked Dec 03 '25 16:12

Utshaw


1 Answers

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.

  1. layout_weight="1" and layout_width="0dp" ==> that particular view will be stretched horizontally if there is not other layout adjacent to it.

  2. 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.

  3. 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.

like image 141
Newbie Android Avatar answered Dec 06 '25 06:12

Newbie Android