Introduction to the working process of "Android-view" View

Source: Internet
Author: User

The work process of view is divided into three processes:

    • The measure process of view;
    • The layout process of the view;
    • The draw process for the view.

We know that an Activity is a window that contains a window, a decorview , and a Viewrootimpl object, All windows in the app are managed by a WindowManager object. Viewrootimpl is the link between WindowManager and Decorview, which can accept messages from WindowManager, pass messages to Decorview,decorview, and distribute the messages. In addition, the three processes of view (measurement, layout, and drawing) are also done in Viewrootimpl.

There is a performtraversals () method in the Viewrootimpl, which in turn calls performmeasure () , performlayout () , Performdraw () Three methods, these three methods to complete the Decorview measure, layout and draw the three major processes. The measure () method is called in the Performmeasure () method, and the onmeasure ( ) method is called in the measure () method; The measure process is performed on all child elements, and this time the measure process is passed from the parent container to the child element, thus completing a measure process. The child element then repeats the measure process of the parent element, which completes the traversal of the entire view treee over and over again. Similarly, the flow of the PerformLayout () method and the Performdraw () method and the Performmeasure () method are similar. The entire process is as shown.

Decoreview is the top-level layout of the entire activity, which by default is a vertically arranged linearlayout, the upper part is called the title bar , and the following part is called the content area , as shown in. As you can see, this is the interface schema that we display when we run the Android program using the default theme. Where the content area is called contents, we can get through viewgroup content = (viewgroup) Findviewbyid (Android. r.id.content) way to find this content layout, which is the layout of the interface written in our project XML file. Therefore, we use the Setcontentview () method to set the layout of the interface in activity instead of using Setview () or setlayout ().

Come back and introduce the three main processes of view:

The measure process determines the width/height of the view. After the measure is complete, we can get the width and height after the view measurement through the getmeasuredwidth () , getmeasuredheight () method. In particular, the width and height after the measurement is wide, not the actual width of the view. Please refer to the "Measure process analysis" for the specific process of the measure process.

The layout process determines the coordinates of the view four vertices and the actual width/height of the view. Once layout is complete, we can use getTop () , getbottom () , getLeft () , and getRight () The four methods get the position of the four boundaries of the view, and the final width/height of the view can also be obtained through the getwidth () and getheight () methods. For details on the layout process, please refer to: "Layout process parsing".

The draw process determines the display of the view. The view can be rendered on the screen only after draw is complete. For the specific process of the draw process, please refer to: "Draw process parsing".

Introduction to the working process of "Android-view" View

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.