用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没什么区别(在我用到的范围内)。

如果这篇博文有帮助到你,或者有什么错误提醒,建议改进的地方,欢迎给我留言。

更多相关文章

  1. Android(安卓)Log 配置解决方案
  2. Android(安卓)Studio的使用总结
  3. android使用mat分析内存泄漏
  4. 安全卫士笔试 第一天
  5. Okhttp的简单介绍和使用(一)
  6. ffmpeg入门教程之Android使用FFmpeg so(封装格式转换)
  7. Android(安卓)JNI 开发简单介绍
  8. Android中Dialog自带蒙层适配状态栏
  9. [android]android自动化测试十一之代码覆盖率报告EMMA

随机推荐

  1. android 录音
  2. Android(安卓)Getting Started
  3. Android(安卓)AppMsg (Crouton) Library
  4. Android(安卓)Handler简单例子
  5. android核心技术之性能分析工具Systrace
  6. Ndk配置与Demo
  7. Android(安卓)screenrecord
  8. android 小知识总结
  9. android 常用颜色对照表
  10. Android(安卓)Button Highlight