LayoutInflater.from(this)的用法--inflate就相当于将一个xml中定义的布局找出来.
来源:互联网 发布:行星和恒星的区别知乎 编辑:程序博客网 时间:2024/06/05 10:46
通俗的说,inflate就相当于将一个xml中定义的布局找出来.
因为在一个Activity里如果直接用findViewById()的话,对应的是setConentView()的那个layout里的组件.
因此如果你的Activity里如果用到别的layout,比如对话框上的layout,你还要设置对话框上的layout里的组件(像图片ImageView,文字TextView)上的内容,你就必须用inflate()先将对话框上的layout找出来,然后再用这个layout对象去找到它上面的组件,如:
Toast toast = new Toast(ToastTest.this);
LayoutInflater inflater = LayoutInflater.from(ToastTest.this);
View view = inflater.inflate(R.layout.toast, null);
LinearLayout ll = (LinearLayout)view.findViewById(R.id.ll);
toast.setView(ll);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
如果组件R.id.dialog_tv是对话框上的组件,而你直接用this.findViewById(R.id.dialog_tv)肯定会报错.
0 0
- LayoutInflater.from(this)的用法--inflate就相当于将一个xml中定义的布局找出来.
- LayoutInflater和inflate()方法的用法 (自定义View中加载xml布局)
- LayoutInflater和inflate()方法的用法 (自定义View中加载xml布局)
- LayoutInflater和inflate()方法的用法 (自定义View中加载xml布局)
- LayoutInflater.from(this)的用法
- LayoutInflater.from(this)的用法
- LayoutInflater.from(this)的用法
- LayoutInflater、inflate的用法
- LayoutInflater.from(this) View.inflate()
- LayoutInflater.from(this) View.inflate()
- LayoutInflater.from(this)、inflate 详解
- LayoutInflater的inflate函数用法
- LayoutInflater和inflate的用法
- LayoutInflater和inflate的用法
- LayoutInflater.inflate的用法总结
- LayoutInflater的inflate函数用法
- LayoutInflater和inflate的用法
- android中LayoutInflater.from(context).inflate的分析
- Redis监控技巧总结
- QWidget,QMainWindow和QDialog的区别
- iOS8中使用CoreLocation定位
- mongodb同关系型数据库的映射对比
- Python 列表
- LayoutInflater.from(this)的用法--inflate就相当于将一个xml中定义的布局找出来.
- shell awk 用法总结
- android 中使用Canvas 画圆
- proguard去掉调试代码
- 解决JSP中文乱码问题
- 打开辣妈萌宝很好地承载了宝宝所有的幸福记录
- c++回调函数 callback
- linux 系统监控、诊断工具之 top 详解
- 使用 Hadoop 和 Hive 获取机器数据