The method inflate () in Android

Source: Internet
Author: User

Inflate () method can find out a layout defined by xml,as like the Findviewbyid () Method,but There has some different betw Een them.


The different are:

If your Activity used other Layout,such as the dialog Layout,and your want to set the component's content in that Layout.yo U must use the inflate () method to find it out,then with the Findviewbyid () method to find other components above It.such a S

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 in dialog layout,if you direct to use the This.findviewbyid (R.ID.DIAOG_TV), it'll throw error.

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

You can imagine it as "hidden inflation", hide placed in View,before inflate () just to find the control,but no size and did N ' t occupy place in the view.

After inflate (), it must has size,but hide.

If you also interest on Linux and Android embed system,please connection with us in QQ grounp:139761394

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.