LayoutInflate: Avoid passing null as the view root
场景:
使用LayoutInflate.inflate()方法加载一个布局,当参数root 为null 时,出现下列提示
Avoid passing null as the view root (needed to resolve layout parameters on the inflated layout's root element)
解决方案:
方法一. 添加suppress:
@SuppressLint("InflateParams")
方法二. 改用View的inflate方法:
view = View.inflate(context,R.layout.custom_layout,null)
原因:
LayoutInflate.inflate使用时要求传递根父布局View,如果传递为null,将会导致正在inflate的layout xml中顶层android:layout_xxx属性失效,因为这些属性是根据父布局View来设定的。
例外的场景是在Dialog中可以传递null值,因为Dialog在创建的时候会默认擦除父布局View
参考:https://web.archive.org/web/20190528213406/https://possiblemobile.com/2013/05/layout-inflation-as-intended/
LayoutInflate: Avoid passing null as the view root相关推荐
- LayoutInflater的错误用法(Avoid passing null as the view root )
今天在练习使用Fragment的时候,注意到在使用LayoutInflater的时候有黄色报警(Avoid passing null as the view root (needed to resol ...
- Avoid passing null as the view root windowManager使用
Avoid passing null as the view root (needed to resolve layout parameters on the inflated layout's ro ...
- Avoid passing null as the view root ;Android
警告提示:Avoid passing null as the view root (needed to resolve layout parameters on the inflated layout ...
- xmodmap: unable to open display '' Error: Couldn't connect to XServer passing null display
/********************************************************************************** xmodmap: unable ...
- LayoutInflater——inflate方法不同参数的区别
LayoutInflater有两个参数inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot),inflate(XmlPu ...
- 关于LayoutInflater.from(context).inflate()的使用的问题
在一般项目中使用adapter时,加载item布局咱们一般会使用: LayoutInflater.from(context).inflate(R.layout.list_item, null): ...
- 深入理解 LayoutInflater.inflate() 方法
目录 1. 前言 2. 正文 2.1 inflate() 方法分析 2.1.1 根节点不是 merge 时,第一组取值情况分析 2.1.2 根节点不是 merge 时,第二组取值情况分析 2.1.3 ...
- linux内核源码git操作简单总结
有个老同事想快速查看不同版本的内核源码,问我有没有啥方法,当然有.大部分玩linux的小伙伴应该都知道从kernel/git/stable/linux.git - Linux kernel stabl ...
- Java Code Convention Rules
2019独角兽企业重金招聘Python工程师标准>>> Java Code Convention Rules Rules available in this category: Av ...
最新文章
- 二十五:设计模式的总结
- Scrapy框架基础使用
- 谈谈C++继承中的重载,覆盖和隐藏
- 'React/RCTBridgeDelegate.h' file not found
- 服务器监控工具_系统管理员不可错过的 6 款服务器监控工具
- cpu居高不下 linux,linux cpu居高不下 调试
- OCP大会 | DCOS – 面向数据中心的运营操作系统(附PPT)
- python tkinter treeview 高亮_满满的成就感~如何用python让你的想法拥有可操作性?(一)...
- 华为发布政企战略及华为云Stack,瞄准新基建下政企的数字化转型
- mysql did not start_mysql 服务无法启动
- URAL 1992 CVS 可持久化链栈
- rsync工具介绍,rsync常用选项,rsync通过ssh同步
- 对《构建之法——现代软件工程》13-17章的困惑与思考
- JS 逻辑中断(一)
- 找不到ADO.NET Entity Data Model模板或 sql server database project模板
- HTML5 web SQL 和indexedDB的使用
- 记录一次众测平台邀请码获取
- Servlet面试题归纳
- TCPMP播放器UI的修改方法
- Problem C: 复数类的流输入输出
热门文章
- R实战 | OPLS-DA(正交偏最小二乘判别分析)筛选差异变量(VIP)及其可视化
- 【WinHex篇】WinHex制作磁盘镜像教程
- 一大早,是什么让技术群发出强人锁男、男上加男、勉为骑男?
- 计算机网络技术毕业生实习报告_计算机网络专业实习报告
- 【Spring AOP】@Aspect结合案例详解(二): @Pointcut使用@within和within(已附源码)
- 用Python让蔡徐坤在我的命令行里打篮球!| 附完整代码
- AD18无法仿真问题的解决
- 洛谷 P1564 膜拜 C++ dp
- c语言visit函数作用,Visit
- 诚之和:SQL Where – 子句示例