Drawing flow for the entire view tree
is the performtraversals () function of the Viewroot.java class that expands the
Performtraversals () execution process
- Determine if the view size needs to be recalculated (measure)
- If you need to place the view again (layout)
- Do I need to redraw (draw)
Mesarue ()
Tree recursion Process
Role
Set the actual width and height "mmeasuredheight, mmeasurewidth" for the entire view tree calculation actual size
Tip the actual width of each view control is determined by the parent trying and itself trying to decide
Call Chain
Viewroot the root object's properties Mview (), measure () = view tree size, callback View/viewgroup object's Onmeasure () method
Implementation features
- Sets the final size of this view. Setmeasureddimension ()--mmeasureheight/mmeasurewidth
- Measure () Procedure for traversing a child view of a ViewGroup type object, overriding the Onmeasure ()
- Child View measure () procedure, calling the Measurechildwithmargins () implementation in parent Viewgroup.java
- Measurechildwithmargins () is just a transition layer
- Simple and straightforward method: View object's measure ()
Layout () function
To place the view tree in the appropriate location based on the size of the child view and layout parameters
Call Chain
Host.layout () Starts the view tree layout and callbacks to layout () in the View/viewgroup class
- Layout (), set the View view in the parent view of the axis, Mleft,mtop,mleft,mbottom (call the setframe() function to implement), and then callback onlayout() Method
- View is ViewGroup, traversing each child view Childview, calls the layout () of the child view to set its coordinate value
Draw () effect
Flag bit drawn: each time the drawing is launched, the flag bit is added to the view, and only those views that need to be redrawn are redrawn
Viewroot-- performtraversals() draw() Draws the view tree,
Invoke process
- Draw background
- Do some preparation for displaying the gradient box
- OnDraw () "Each view needs to reload the method, ViewGroup does not need to implement the method"
- Dispatchdraw () Draw child attempt (ViewGroup rewrite Dispatchdraw (), application can overload the parent class function to implement specific functions)
- The Dispatchdraw () method iterates through each child view and calls Drawchild () to recall the draw () method of each child view
- scroll bar
Performtraversals () Execution process trigger function
Google has already written the draw () process framework for us, and the custom viewgroup only needs to implement the measure () process and the layout () process.
These three cases will eventually call directly or indirectly to three functions
- Invalidate ()
- Requsetlaytout ()
- Requestfocus ()
Then the three functions are eventually called to the Schedultraversale() method in Viewroot, which then initiates an asynchronous message that calls the Performtraverser () method in the message processing to traverse the entire view.
Invalidate ()
Call the Draw () procedure and do not call the layout () procedure if the size of the view does not change, and draw only those views that need to be redrawn
The view is drawn for who (view, only draws the view; ViewGroup, then draws the entire viewgroup) request invalidate ().
The function that normally causes the invalidate () operation is as follows:
- Invalidate (): Request Redraw (), but only the caller itself is drawn.
- SetSelection (): Request Redraw (), but only the caller itself is drawn.
- Setvisibility (): When the view visual state transitions to visible in invisible, the Invalidate () method is called indirectly and the view is drawn.
- SetEnabled (): Request re-draw (), but do not redraw any views including the caller itself.
Requestlayout ()
Just to rearrange the layout process on the view tree, call the measure () procedure and the layout () procedure and not redraw any views including the caller itself.
The function that normally causes the requestlayout () operation is as follows:
- Setvisibility () Method:
- Requestlayout () and invalidate () are called indirectly when the visual state of the view is converted to the gone state in invisible/visible.
- Also, because the entire view tree size has changed, the measure () process and the draw () process are requested, as well as drawing only the views that need to be redrawn.
Requestfocus ()
Request the Draw () procedure for the view tree, but only the view that needs to be redrawn is drawn
http://blog.csdn.net/qinjuning/article/details/7110211/Thanks for thanking
Drawing flow of Androidview tree