Application of Inflate () method in Android Layoutinflater _android

Source: Internet
Author: User

the Android Inflate () method is used to find a layout of the XML definition , but only to find and hide, not to find, and to display the functionality. One of the most recent projects I've been doing this is confusing me for days.

Android also has a similar approach to inflate () called Findviewbyid (), which can sometimes be used interchangeably, but there are differences:

If you use other layout in your activity, such as a dialog box layout, and you want to set the content of the other components on the layout, you have to use the inflate () method to find the layout of the dialog box and then use Findviewbyid () Find the other components above it. For example:

View view1=view.inflate (this,r.layout.dialog_layout,null);
textviewdialogtv= (TextView) View1.findviewbyid (R.ID.DIALOG_TV);
Dialogtv.settext ("ABCD");

Note: R.ID.DIALOG_TV is a component on the layout of the dialog box, and if you use This.findviewbyid (R.ID.DIALOG_TV) you will get an error.

View viewstub = ((viewstub) Findviewbyid (R.id.stubview)). Inflate ();

Inflate () can be understood as "recessive expansion", hidden in view, inflate () before just get control, but no size does not occupy the space in the view, inflate () after a certain size, just in the hidden state.

The above is a simple description of the Android Inflate () method, hoping to help students in need.

Related Article

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.