LayoutInflater.from(parent.context).inflate(R.layout.activity_main,parent,false)
通过CTRL+用鼠标点击from方法我们进入了from源码(windows快捷键,Mac为Command+c)
public static LayoutInflater from(Context context) {
LayoutInflater LayoutInflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (LayoutInflater == null) {
throw new AssertionError(“LayoutInflater not found.”);
}
return LayoutInflater;
}
从Android Developers我们找到了定义: 从给定的上下文获取LayoutInflater。 如果为空,抛出异常 
在讨论.inflate(R.layout.activity_main,parent,false)
从Android Developer我们看到有四个inflate方法,但其实最多只有三个参数


这里我们主要分析三个参数的inflate,这里用了官方的解释
1
LayoutInflater深度解析,学习方式分享
本文详细解析了LayoutInflater的使用方法,包括from方法的功能及inflate方法的三种参数含义,并提供了具体的应用场景说明。

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



