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)

解决方案:

1. 添加:

@SuppressLint("InflateParams")

2. 修改成

view = View.inflate(context,R.layout.custom_layout,null);

改用View的inflate方法root为null就不会出现warning提示。

参考链接:
1. Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element)

猜你喜欢

转载自www.cnblogs.com/yongdaimi/p/12166138.html