Android如何用代码重复加载同一个xml
16lz
2021-01-26
用LayoutInflater多次inflate该xml文件即可。
View v1 = LayoutInflater.from(context).inflate(R.layout.XXX, null);View v2 = LayoutInflater.from(context).inflate(R.layout.XXX, null);
这里修改v2内容是不会改变v1的。
接下来是故事起由
开始查找的时候被《Android: How to add another layout number of time to my already created LinerLayout?》误导,以为要用
LinearLayout llItem=(LinearLayout)LayoutInflater.createFromSource(R.layout.child, null);
来创建新的资源文件的实例。
可实际上LayoutInflater并没有createFromSource这个方法。于是查找LayoutInflater的API,看到个貌似有复制意思的cloneInContext(Context newContext)
,实验结果和直接用inflate没什么区别(在我用到的范围内)。
如果这篇博文有帮助到你,或者有什么错误提醒,建议改进的地方,欢迎给我留言。
更多相关文章
- Android(安卓)Log 配置解决方案
- Android(安卓)Studio的使用总结
- android使用mat分析内存泄漏
- 安全卫士笔试 第一天
- Okhttp的简单介绍和使用(一)
- ffmpeg入门教程之Android使用FFmpeg so(封装格式转换)
- Android(安卓)JNI 开发简单介绍
- Android中Dialog自带蒙层适配状态栏
- [android]android自动化测试十一之代码覆盖率报告EMMA