Activity 中加载布局文件
是在 onCreate 方法中:setContentView(R.layout.activity_main);
Fragment 中加载布局文件
是在 onCreateView 是方法中:inflater.inflate(R.layout.fragment_list, container, false);
自定义控件中加载布局文件
是在构造函数中:LayoutInflater.from(context).inflate(R.layout.component_bottom_navigation, this, true);
注意最后一个参数 attachToRoot。
Fragment、自定义控件中使用 findViewById
加载布局时都会返回 view,用 view.findViewById。