Layoutinflater.inflate Source Code Analysis

Source: Internet
Author: User

Based on the analysis of Android 4.2.2, the DOM object of layout is encapsulated in the parser, from which we can get the parent node of each node's root for layout, and its function is explained in the above document, it is important to note that There are two main functions of root: 1. Based on the root type (relativelayout/linearlayout), combined with the layout configuration of Attrs to create layoutparams, such as root for Relativelayout, Toleftof is set in layout, the Relativelayout.layoutparams createdThis property is saved in the. 2. For layout ViewGroup set the Layoutparams for layout of child nodes, using recursive function set here the main analysis of the params = Root.generatelayoutparams (attrs); and Temp.setlayoutparams (params); Assuming that the root type is relativelayout, The generatelayoutparams is called as follows: its parent class is viewgroup.marginlayoutparams, and its constructor is as follows: You can see that the basic properties of the Layoutparams object are set in the parent class based on attrs: width, height, Margin while the subclass is responsible for relativelayout specific property settings, such as the Below/toleftof/above/alignxxx property: If the top node in the layout file is as follows, and its root is relativelayout, The above action is to set the properties within the red box, and the Setlayoutparams function is to make it effective. The function is described as follows: the mparent here is root.In the case of Attach=false, the role of root is to make the layout of the Layout_params effective, recommended in oncreate/oncreateview/ Oncreatecontentview inflate use the root parameter to avoid layout invalidation. For example, the layout of the top node android:layout_height= "184DP", but if inflate when root=null, the actual display layout_xxx does not take effect ref:http://blog.csdn.net/ xyz_fly/article/details/37932989

Layoutinflater.inflate Source Code Analysis

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.