Android weight attribute
It's just freaking me out, but I can't make my layout depend on weight. There are two relative layouts and two linear layouts and some elements in both of these layouts. I've put android:layout_weight="0.2
to the first one, android:layout_weight="0.1
to the second one, android:layout开发者_开发技巧_weight="0.5
to the third one, and android:layout_weight="0.2
to the last one. The sum is 1, right? But it doesn't work. I'm afraid, it's because of different layout_height and maybe different categories of layouts? The XML-code is here
My experience with the layout_weight attribute is the following: Set all layout_height (or width depends on what you are doing) to fill_parent or wrap_content (it should be the same value for all elements). Try both versions. Sometimes wrap_content is better sometimes fill_parent is better.
There are many theories about the mystic of the layout_weight attribute. This is my version^^
Edit: I forgot to mention, that the logic is inverted: the less weight the bigger the element.
I have experienced that setting the width or height (depending on which direction you want your layouts to span) to 0 can be usefull from time to time.
It is possible that you might need to use the value "0.4f", when you use values > 1.
You could also try setting the weight_sum
to an amount (in your example it could be 10) and then use the layout_weight
values 2, 1, 5 and 2 - but I'm not sure that it will make a difference.
精彩评论