开发者

Linear Layout - Difference between weight and FILL_PARENT

开发者 https://www.devze.com 2023-01-08 21:01 出处:网络
According to documentaion, FILL_PARENT basically lets the view take up the entire extra space. Weigh开发者_Go百科t also dictates how much of the extra space can be taken by the view. What is the diffe

According to documentaion, FILL_PARENT basically lets the view take up the entire extra space. Weigh开发者_Go百科t also dictates how much of the extra space can be taken by the view. What is the difference?

For eg: What happens when I use,

new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f)


FILL_PARENT makes it take up all available space. Weight makes it take up a relative amount. Example: say you have two boxes, A and B, added to a horizontal LinearLayout in that order. If A is set to WRAP_CONTENT and B is set to FILL_PARENT, your layout is

[A][+++++B+++++]

Whereas if you instead have A's weight set to 2 and B's weight set to 2, you get

[++A++][++B++]

If you have A's weight set to 2 and B's weight set to 4 you get

[+A+][+++B+++]

etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号