6. Android Layoutinflater.inflate ()

Source: Internet
Author: User

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 ()

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.