user2224350
user2224350

Reputation: 2334

Does addView() invoke onMeasure() for all childs?

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

Upvotes: 3

Views: 1154

Answers (1)

Yaroslav Mytkalyk
Yaroslav Mytkalyk

Reputation: 17115

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.

Upvotes: 2

Related Questions