码迷,mamicode.com
首页 > 移动开发 > 详细

The method Inflate() in android

时间:2014-06-22 06:41:43      阅读:362      评论:0      收藏:0      [点我收藏+]

标签: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,布布扣,bubuko.com

The method Inflate() in android

标签:android

原文地址:http://blog.csdn.net/xiebaochun/article/details/32935895

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!