The method Inflate() in android

简介: <p>Inflate() method can find out a layout defined by xml,as like the findViewById() method,but there have some different between them.</p> <p><br></p> <p>The different are:</p> <p>If your Activ

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

相关文章
|
Android开发
Android LayoutInflater.from(context).inflate()方法的作用
Android LayoutInflater.from(context).inflate()方法的作用
87 0
|
API Android开发 Windows
Android P下WindowManager与LayoutParams的详解
WindowManager是什么?WindowManager与window的关系是什么?
794 0
|
消息中间件 Android开发
Android中Handler的正确使用
在Android常用编程中,Handler在进行异步操作并处理返回结果时经常被使用。通常我们的代码会这样实现。 public class SampleActivity extends Activity { private final Handle...
1456 0
|
Android开发 安全
|
Android开发 Java 存储
Android Context 干货
image.png 一、源码角度解析Context 从系统的角度来理解:Context是一个场景,代表与操作系统的交互的一种过程。Context是一个抽象类;Activity、Service、Application是它的子类; image.png 二、Context 应用场景 image.png 数字1:启动Activity在这些类中是可以的,但是需要创建一个新的task。
1097 0