The method Inflate() in android

Posted cynchanpin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The method Inflate() in android相关的知识,希望对你有一定的参考价值。

Inflate() method can find out a layout defined by xml,as like the findViewById() method,but there have some different between them.


The different are:

If your Activity used other layout,such as the dialog layout,and you want to set the component‘s content in that layout.you must use the inflate() method to find it out,then use the findViewById() method to find other components above it.such as:

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 will 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 didn‘t occupy place in the view.

after inflate(),it must have size,but hide.

if you also interest in linux and android embed system,please connection with us in QQ grounp:139761394





以上是关于The method Inflate() in android的主要内容,如果未能解决你的问题,请参考以下文章

The method sort(Comparable[]) in the type Shell is not applicable for the arguments (int[])

Calling a method in the system process without a qualified user

The method below converts an array of objects to a DataTable object in C#.

Android代码异常Calling a method in the system process without a qualified user

Android代码异常Calling a method in the system process without a qualified user

Cannot assign to 'self' outside of a method in the init family