3

does adding a child to a ViewGroup (via ViewGroup.addView() ) automatically invoke onMeasure() for all childs?

user2224350
  • 2,262
  • 5
  • 28
  • 54

1 Answers1

2

ViewGroup should measure it's width and height by first measuring all children. If ViewGroup's width or height is wrap_content it will call onMeasure() for all children for sure. Can't say that about match_parent. One thing for sure that addView() calls requestLayout() which will re-calculate layout children's position call layout(l, t, r, b) on all children.

To know for sure if it calls you can create a custom View and log every call to onMeasure() and add those to a ViewGroup. Could be that different ViewGroup implementation will act differently.

Yaroslav Mytkalyk
  • 16,950
  • 10
  • 72
  • 99