android inflate作用
来源:互联网 发布:中文版编程软件 编辑:程序博客网 时间:2024/05/14 12:14
通俗的说,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)
因为在一个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)
- android inflate作用
- android inflate作用
- android Inflate 的作用
- Android中的inflate作用
- Android:inflate.inflate()方法
- Android LayoutInflater的inflate方法中attachToRoot的作用
- Android LayoutInflater的inflate方法中attachToRoot的作用
- Android LayoutInflater的inflate方法中attachToRoot的作用
- Android Inflate
- Android inflate
- 【Android 界面效果43】Android LayoutInflater的inflate方法中attachToRoot的作用
- 【android Inflate】 Android中inflate简介
- Android编程之LayoutInflater的inflate方法详解及其中参数的作用
- Inflate()---Android之Inflate()方法用途
- 【Android】【Inflate】inflate方法的三个参数
- Inflate()---Android之Inflate()方法用途
- Android 关于inflate
- Android--关于inflate()方法
- 编程论坛手机客户端 ~太强悍了
- Python:程序发布方式简介一(打包为可执行文件EXE)
- Problem install fedora with liveusb
- Android Menu菜单
- 查看Linux系统内存 CUP 使用情况
- android inflate作用
- 今年的读书计划
- linux vi常用命令---1
- Android中HAL如何向上层提供接口总结 .
- Vim快捷键
- 毕业九个月时的再思考:什么是重要的事
- Apache 403 error, (13)Permission denied: access to / denied问题
- Effective C++读书笔记(25)
- 【Floyd求最短路+快速幂】PKU-3613-Cow Relays