Parameters and usage of Android Layoutinflater.inflate ()

Source: Internet
Author: User

Content from: http://blog.csdn.net/lovexieyuan520/article/details/9036673

Many people on the Internet Ask Layoutinflater class usage, and the meaning of the inflate () method parameters, are explained as follows:

The role of inflate () is to find a layout file defined in XML, noting the difference between Findviewbyid (), inflate is loading a layout file, and Findviewbyid is looking for a control from the layout file.

1. There are three ways to get Layoutinflater objects

Layoutinflater Inflater=layoutinflater.from (this);
Layoutinflater Inflater=getlayoutinflater ();
Layoutinflater inflater= (Layoutinflater) This.getsystemservice (Layout_inflater_service);

2. Aboutthe meaning of three parameters of Layoutinflater class inflate (int resource, ViewGroup root, Boolean Attachtoroot) method

Resource: The ID of the layout file needs to be loaded, meaning that the layout file needs to be loaded into the activity to operate.

Root: The root control that needs to be attached to the resource resource file, what does it mean that inflate () returns a View object, and if the third argument is Attachtoroot true, the root is returned as the root object, Otherwise, simply append the Layoutparams attribute of the root object to the root layout object of the resource object, which is the outermost view of the layout file resource, such as a linearlayout or other layout object.

Attachtoroot: Whether to attach root to the root view of the layout file

This is my understanding, if you do not understand or wrong, please the vast numbers of netizens to my message, common progress!

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.