One view: the rendering process of viewgroup
Viewgroup painting involves two steps: 1. Measure 2. Layout
Call the callback function in these two steps: 1. onmeasure () 2. onlayout ()
1. onmeasure () in this function, viewgroup will accept the size of the childview request, and store it in childview through the measure (newwidthmeasurespec, heightmeasurespec) function of childview, so that getmeasuredwidth () of childview ()
The value of andgetmeasuredheight () can be obtained by subsequent work.
2. onlayout () in this function, viewgroup will get getmeasuredwidth () and getmeasuredheight () of childview to layout all childview.
3. View. measurespec and layoutparams are used to negotiate the sizes of viewgroup and childview. Here, view. measurespec is used by viewgroup to deploy childview, and layoutparams is used by childview to tell the viewgroup where I need it.
4. At the end of onmeasure of the view, call setmeasureddimension () to store the size of the view. This method determines the size of the current view.
Second view: the sequence and usage of viewgroup gesture monitoring
Callback Function of the view gesture listener: ontouchevent ()
Callback functions related to viewgroup gesture listening: ontouchevent (), onintercepttouchevent ()
1. Both callback functions return a Boolean variable, indicating whether the gesture is consumed. If consumption is completed, true is returned. If consumption is not performed, false is returned.
2. When you touch the screen, a motionevent is generated, and onintercepttouchevent () of viewgroup accepts this motionevent.
If this callback function returns true, it indicates that this viewgroup consumes this gesture and does not want to allow its childview to process it any more. The childview ontouchevent () will no longer accept this gesture, at the same time, the ontouchevent () of this viewgroup accepts this gesture.
If this callback function returns false, it indicates that this viewgroup has not consumed this gesture and wants its childview to process it. childview's ontouchevent () accepts this gesture, at the same time, the ontouchevent () of this viewgroup does not accept this gesture.
3. The ontouchevent () value indicates that the event is passed up, And the onintercepttouchevent () value indicates that the event is passed down.