Which of the following best describes the crucial difference in how `onMeasure` functions within a `ViewGroup` versus a `View`?
Android interview question for Advanced practice.
Answer
A View's onMeasure only considers its own dimensions, while a ViewGroup's onMeasure recursively measures its children and sums their sizes.
Explanation
The key difference lies in the recursive nature of onMeasure in a ViewGroup. A View measures only its own dimensions based on its content and layout parameters. A ViewGroup, however, must also measure each of its children before determining its own size. This recursive measurement process is fundamental to the layout hierarchy.