LayoutInflater.from(this)、inflate 详解
来源:互联网 发布:linux无ip 编辑:程序博客网 时间:2024/06/04 18:49
三种方式可以生成LayoutInflater
LayoutInflater inflater = LayoutInflater.from(this);
LayoutInflater inflater = getLayoutInflater();
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
然后调用inflate方法将xml布局文件转成View
public View inflate (int resource, ViewGroup root, boolean attachToRoot)
在View类中,也有inflate方法
LayoutInflater inflater = LayoutInflater.from(this);
LayoutInflater inflater = getLayoutInflater();
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
然后调用inflate方法将xml布局文件转成View
public View inflate (int resource, ViewGroup root, boolean attachToRoot)
在View类中,也有inflate方法
public static View inflate (Context context, int resource, ViewGroup root)
通俗的说,inflate就相当于将一个xml中定义的布局找出来.
因为在一个Activity里如果直接用findViewById()的话,对应的是setConentView()的那个layout里的组件.
因此如果你的Activity里如果用到别的layout,比如对话框上的layout,你还要设置对话框上的layout里的组件(像图片ImageView,文字TextView)上的内容,你就必须用inflate()先将对话框上的layout找出来,然后再用这个layout对象去找到它上面的组件,如:
View view = View.inflate(this, R.layout.dialog_layout, null);
TextView dialogTV = (TextView) view.findViewById(R.id.dialog_tv);
dialogTV.setText("abcd");
如果组件R.id.dialog_tv是对话框上的组件,而你直接用this.findViewById(R.id.dialog_tv)肯定会报错.
- LayoutInflater.from(this)、inflate 详解
- LayoutInflater.from(this) View.inflate()
- LayoutInflater.from(this) View.inflate()
- LayoutInflater.from(this).inflate()参数解析
- LayoutInflater inflate参数详解
- LayoutInflater.inflate详解
- LayoutInflater 的inflate详解
- android LayoutInflater.inflate详解
- LayoutInflater.inflate详解
- LayoutInflater.inflate详解
- LayoutInflater.inflate详解
- LayoutInflater.inflate详解
- LayoutInflater inflate参数详解
- LayoutInflater.inflate源码详解
- LayoutInflater.inflate详解
- LayoutInflater#inflate()方法详解
- LayoutInflater.inflate参数详解
- View.Inflate)与LayoutInflater.from().inflate();
- 淘宝实战干货:升客户体验,让DSR保持高位运行
- XMPP使用tls 和sasl登录
- 输入一个字符串内有数字和非数字字符,将连续的数字作为一个整数,存到数组a中,统计整数的个数,并输出这些数
- amssbuildingbylight
- MFC获取文件夹下的所有文件名
- LayoutInflater.from(this)、inflate 详解
- android利用Http协议实现从网络上面获取图片的方法
- jQuery前端技术应用
- int atoi(const char *str)库函数实现
- android的国际化和本地化
- 百度笔试题1
- 使用chroot构建linux沙盒
- 一些的网站(持续)
- struts2使用插件(jfreechart图表插件)