Drawing flow of Androidview tree

Source: Internet
Author: User

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
    1. Sets the final size of this view. Setmeasureddimension ()--mmeasureheight/mmeasurewidth
    2. Measure () Procedure for traversing a child view of a ViewGroup type object, overriding the Onmeasure ()
      1. Child View measure () procedure, calling the Measurechildwithmargins () implementation in parent Viewgroup.java
      2. Measurechildwithmargins () is just a transition layer
      3. 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

    1. 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
    2. 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
    1. Draw background
    2. Do some preparation for displaying the gradient box
    3. OnDraw () "Each view needs to reload the method, ViewGroup does not need to implement the method"
    4. Dispatchdraw () Draw child attempt (ViewGroup rewrite Dispatchdraw (), application can overload the parent class function to implement specific functions)
      1. The Dispatchdraw () method iterates through each child view and calls Drawchild () to recall the draw () method of each child view
    5. 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:

    1. Invalidate (): Request Redraw (), but only the caller itself is drawn.
    2. SetSelection (): Request Redraw (), but only the caller itself is drawn.
    3. Setvisibility (): When the view visual state transitions to visible in invisible, the Invalidate () method is called indirectly and the view is drawn.
    4. 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:

    1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.