views:

142

answers:

1

Taken from the Android documentation about LayoutParams:

FILL_PARENT, which means the view wants to be as big as its parent (minus padding)

WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding)

Now, if the parent sets its height to wrap_content, and the child sets its height to fill_parent, what does that actually mean? I mean, this sounds like a "tie" between size requests: the child wants to be as big as its parent, but the parent wants to be as big as its child.

I've read How Android Draws Views, but the article doesn't explain how layout params and MeasureSpecs actually work together.

+1  A: 

Basically MeasureSpecs are about size, and LayoutParams helps parent view to distribute available size between its children.
Well basically it works somehow this way: Presume ViewHierachy P0 - P1 - C0,C1 ( P for parent, C for child)
1) P0 calls measure of P1 with some MeasureSpecs ( depends on LayoutParams of P1)
2) in onMeasure call of P1 , P1 knows how large it can be from measure specs provided by P0
3) P1 need to tell it children their size based of LayoutParams of each child for example: Child (C0) has LayoutParams.width = "FILL_PARENT" and P1 is LinearLayout with vertical align, so P1 can tell it C0 child MeasureSpec.AT_MOST with it's one width. To determine height of each child P1 knows: child count, LayoutParams of each child , and gravity of each child ( if any) so it can distribute available height between it's children.

Hope it helps, for more in depth approach you can see LinearLayout.onMeasure method it has some comments that will help you understand thats happening.

Nikolay Ivanov