views:

182

answers:

1

According to documentaion, FILL_PARENT basically lets the view take up the entire extra space. Weight 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)
+1  A: 

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.

infinitypanda
So when you say, FILL_PARENT takes up all available space, what happens to components added before the view? Does the view cover them all up? How to prevent this?
Chris
The components added before are untouched. It takes up all free space at the moment it's added.
infinitypanda