如果我在 Android 的 inflate 方法中传入 null 作为 2 参数和 true 作为 3 参数会怎样

What will if i pass in a null as 2 parameter and true as 3 parameter in inflate method in Android

如果我在 Android 的 inflate 方法中传入 null 作为 2 参数和 true 作为 3 参数会怎样? 我知道如果我这样做:

LayoutInflater.from(this).inflate(R.layout.children, parent)

R.layout.children 将显示为 parent 的 children。我做对了吗? 但是如果我这样通过

LayoutInflater.from(this).inflate(R.layout.children, null, false)

它会 return 我一个 R.layout.children,没有 parent,因为 parent 作为 null 传递。 但是如果我就这样过去了呢?

LayoutInflater.from(this).inflate(R.layout.children, null)

R.layout.children as children 应该加入什么?其中parent为null,第三个参数默认为true。也就是隐式会有一个addView。但是为了什么?

这是 inflate 的源代码:

    public View inflate(@LayoutRes int resource, @Nullable ViewGroup root) {
        return inflate(resource, root, root != null);
    }

你可以看到 root 是可选的,如果 null 第三个参数是 false 那么没有视图附加到父 ViewGroup。