I am creating the custom viewgroup. While executing the code, the onMeasure function of custom viewgroup is called multiple time. And the measure mode also changed while onMeasure call. For example,(my understanding) If 'match_parent' is set in xml, the measure mode is AT_MOST right. At this time why the both AT_MOST and EXACTLY called. Please help me to understand correctly.
Asked
Active
Viewed 2,426 times
1 Answers
0
It depends on the parent. Some ViewGroups will measure their children twice because they cannot determine how to lay out all of their children with just a single measure pass.

Karakuri
- 38,365
- 12
- 84
- 104
-
1Thanks karakuri. But why the measurement mode is changing every time while on measure process(onMeasure) . – Jayaprakash Marshal Nov 05 '14 at 08:41
-
There is no requirement that the MeasureSpec mode be the same every time. The ViewGroup could be measuring once to see how large the child wants to be, then measure again with a different mode after deciding how much space it can give the child. – Karakuri Nov 05 '14 at 16:16
-
could you give an practical example for "measure twice"? – LiangWang Dec 28 '14 at 11:15
-
A ViewGroup that constrains its child to a certain aspect ratio. In fact such a thing already exists, just do a search for "android ProportionalLayout" – Karakuri Dec 29 '14 at 00:40