The documentation says something to the effect of “onMeasure() is called to determine the size of the view.” and “onLayout() is called to set the size and position of the child views.” The problem is that onMeasure() is called before onLayput() and never after it. How can a view ever calculate its own size using the layout of its children if the size has already been reported before the layout is done?

I never found a documented resolution to this problem. No matter what I did, I could not get onMeasure() to get called after onLayout() even by calling functions like invalidate() or forceLayout() at the end of onlayout(). The solution I came up with was to call my own layout function (although I probably could have called onLayout() directly) and then set the size and position of all of the child views in that function. I should have kept track if I needed to do this in onMeasure() more than once. But I assumed that the system is not going to ask for measurements more than once unless something has changed.

I was thinking of posting a question about this on StackOverflow but I suspect that no one would have a good response. The times I have asked about this stuff, I have not gotten much good feedback. In this case, it’s likely that my solution would be the only solution.

As for improvements, I could have calculated the layout mathematically in onMeasure() and then actually changed the positions of the children in onLayout(). It can’t really make a difference though, since the system won’t use the sizes and positions of those child views until it wants to actually show them on the screen.