Android Note: inflate three parameters and how to use them

Source: Internet
Author: User
<span id="Label3"></p><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><span style="font-size:18px;">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.</span></p></p><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><span style="font-size:18px;"><br></span></p></p><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><span style="font-size:18px;">1. There are three ways to get Layoutinflater objects</span></p></p><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><span style="font-size:18px;color:rgb(255,0,0);">Layoutinflater Inflater=layoutinflater.from (this);<br>Layoutinflater Inflater=getlayoutinflater ();<br>Layoutinflater inflater= (layoutinflater) This.getsystemservice (layout_inflater_service);</span></p></p><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><span style="font-size:18px;color:rgb(255,0,0);"><br></span></p></p><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><span style="font-size:18px;">2. About the meaning of three parameters of Layoutinflater class inflate (int resource<span class="normal"></span>, ViewGroup root, boolean Attachtoroot) method</span></p></p><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><span style="font-size:18px;color:rgb(255,0,0);">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.</span></p></p><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><span style="font-size:18px;color:rgb(255,0,0);">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.</span></p></p><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><p style="color:rgb(54,46,43);font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:rgb(255,255,255);"><span style="font-size:18px;color:rgb(255,0,0);">Attachtoroot: whether to attach root to the root view of the layout file</span></p></p><p><p><br></p></p><p><p>Reference: http://blog.csdn.net/lovexieyuan520/article/details/9036673</p></p><p><p><br></p></p><p><p><br></p></p><p><p>This article from the "sky no traces but I flew" blog, please be sure to keep this source http://glblong.blog.51cto.com/3058613/1675563</p></p><p><p>Android Note: inflate three parameters and how to use them</p></p></span>

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.