The function of Layoutinflater.inflate () is to instantiate an XML-defined layout file as a view control object;
Differences from Findviewbyid:
Layoutinflater.inflate is to load a layout file;
Findviewbyid is to find a control from the layout file;
I. There are three ways to get Layoutinflater objects
Layoutinflater Inflater=layoutinflater.from (context);
Layoutinflater Inflater=getlayoutinflater (); can be used in activity, is actually a function of the window under the view sub-class
Layoutinflater inflater= (Layoutinflater) Context.getsystemservice (Layout_inflater_service);
Two: Inflate parameters
Public View Inflate (int resource, ViewGroup root, Boolean attachtoroot):
Resource:view's layout id root: The root control that needs to be attached to the ReSource resource file, inflate () returns a View object if the third argument
Attachtoroot is true to return this root as the root object, or simply append the root object's Layoutparams property to the root layout object of the resource object
On the outermost view of the layout file resource. If Root is null, the Layoutparams property of the view root object is ignored (note).
Attachtoroot: Whether to attach root to the root view of the layout file
In simple terms:
1. If root is null,attachtoroot will lose its function and setting any value is meaningless.
2. If root is not null andAttachtoroot is set to True, the root layout is then nested in the outermost layer of the loaded layout file.
3. If root is not null andAttachtoroot is set to False, the root parameter loses effect.
4. Without setting the attachtoroot parameter, if root is not NULL, theattachtoroot parameter defaults to TRUE.
6. Android Layoutinflater.inflate ()