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