0

I have following structure in a layout fragment.

FrameLayout (height: wrap content)
    |
    |--> LinearLayout (height: match parent)
    |      |
    |      |--> TextView (height: wrap content)
    |      |
    |      |--> SomeOtherView (height: wrap content)
    |
    |--> View (height: match parent)

The total height taken by this fragment is the height of TextView and SomeOtherView. My question is, because outermost FrameLayout has height as wrap content and its children has height as match parent, wouldn't it create a dilemma on calculating the height? What is the rule which decides the height in this case?

Lahiru Chandima
  • 22,324
  • 22
  • 103
  • 179

2 Answers2

1

That's an interesting question, makes you think about what you usually take for granted :)

From my experience, the overall layout will follow the FrameLayout's height specification, that is "big enough to enclose its children + padding".

Concerning your second question, here's what the official documentation says:

Drawing the layout is a two pass process: a measure pass and a layout pass. The measuring pass is implemented in measure(int, int) and is a top-down traversal of the View tree. Each View pushes dimension specifications down the tree during the recursion. At the end of the measure pass, every View has stored its measurements. The second pass happens in layout(int, int, int, int) and is also top-down. During this pass each parent is responsible for positioning all of its children using the sizes computed in the measure pass.

And also:

The measure pass uses two classes to communicate dimensions. The ViewGroup.LayoutParams class is used by View objects to tell their parents how they want to be measured and positioned.

As a simplification, I think it's safe to say that a child's height is considered by its parent as some kind of a suggestion, not an order, and the parent's dimension takes precedence.

AndroidEx
  • 15,524
  • 9
  • 54
  • 50
1

combining wrap_content on parent and fill_parent on child

Apparently this logic works on linear layout and frame layout as of honeycomb.

Community
  • 1
  • 1
Clocker
  • 1,316
  • 2
  • 19
  • 29