inflate理解
来源:互联网 发布:photoshop软件购买 编辑:程序博客网 时间:2024/06/07 01:28
来源:http://android.tgbus.com/Android/tutorial/201104/348009.shtml
通俗的说,inflate就相当于将一个xml中定义的布局找出来.
因为在一个Activity里如果直接用findViewById()的话,对应的是setConentView()的那个layout里的组件.
因此如果你的Activity里如果用到别的layout,比如对话框上的layout,你还要设置对话框上的layout里的组件(像图片ImageView,文字TextView)上的内容,你就必须用inflate()先将对话框上的layout找出来,然后再用这个layout对象去找到它上面的组件,如:
Viewview=View.inflate(this,R.layout.dialog_layout,null);
TextViewdialogTV=(TextView)view.findViewById(R.id.dialog_tv);
dialogTV.setText("abcd");
如果组件R.id.dialog_tv是对话框上的组件,而你直接用this.findViewById(R.id.dialog_tv)肯定会报错.
三种方式可以生成LayoutInflater:
LayoutInflaterinflater=LayoutInflater.from(this);
LayoutInflaterinflater=getLayoutInflater();
LayoutInflaterinflater=(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
然后调用inflate方法将xml布局文件转成View
publicViewinflate(intresource,ViewGrouproot,booleanattachToRoot)
在View类中,也有inflate方法
publicstaticViewinflate(Contextcontext,intresource,ViewGrouproot)
- inflate理解
- inflate函数的理解
- Android LayoutInflater inflate 理解
- inflater.inflate的理解
- 深入理解LayoutInflater.inflate()
- 深入理解LayoutInflater.inflate()
- 深入理解LayoutInflater.inflate()
- 深入理解LayoutInflater.inflate()
- Android inflate 方法理解
- 深入理解LayoutInflater.inflate()
- inflater.inflate()方法的理解
- android 深入理解LayoutInflater.inflate()
- (转)深入理解LayoutInflater.inflate()
- inflate
- inflate
- inflate
- inflate
- inflate
- 云计算“三国时代”
- Unity网络多玩家游戏开发教程第1章Unity自带网络功能
- 集成产品开发-1
- 简单入门java多线程<一>:源码分析Thread和Runnable
- 小甲鱼PE详解之IMAGE_DOS_HEADER结构定义即各个属性的作用(PE详解01)
- inflate理解
- git发布代码到github
- “android library projects cannot be launched”错误
- Oracle--IE登录OEM显示证书错误
- 最大子序列和,最长递增子序列,最长公共子串,最长公共子序列,字符串编辑距离,最长不重复子串,最长回文子串
- c语言类型转换注意事项
- Servlet跳转页面,怎么跳出框架frameset
- Android基于SOAP协议向WebService交互数据,修改请求超时时间
- “This text field does not specify an inputType or a hint”错误