ViewGroup definition
In the API is so descriptive of the narrative viewgroup: a viewgroup is a special view, can contain other views. According to the meaning we can be clear. Other UI controls can be included in ViewGroup. Including our own definition of the control
Advantages and Uses
We understand that the most important purpose of a UI control is to use it. And to understand the controls. The strength of the control must be clarified.
ViewGroup is relatively complex in Android UI controls, and its own definition is very high. By using Declare-styleable to define control properties, it is possible to control almost every convenience of a control.
With these strengths in mind, where do you think you can find ViewGroup? Think about it and I'll talk about my understanding at the end of the article.
Drawing process
There are two and important callback methods in ViewGroup
- onmeasure (int widthmeasurespec, int heightmeasurespec)
- OnLayout (Boolean changed, int left, int top, int. right, int bottom)
Onmeasure
Ask all children to measure themselves and compute the measurement of this layout based on the children.
OnLayout
Position all children within this layout.
The above is an explanation of the two methods in the API. Both Onmeasure and onlayout can be called multiple times in real-world use. According to log we will find that onlayout are called after Onmeasure, which also confirms the API's argument, ViewGroup before drawing the value of the good, and then according to the corresponding values to draw the control to the corresponding place.
Getmeasuredwidth
This method is presented here alone for a moment. When the control is stored in the Onmeasure method. We will use Getmeasuredwidth () and Getmeasuredheight (), where the resulting value contains padding, does not include margin, and should be noted when calculating
Android ViewGroup Usage Summary