1.activity中
用
LayoutInflater inflater = getLayoutInflater();或者LayoutInflater inflater = LayoutInflater.from(getContext());
获取LayoutInflater实例(也就是activity文件与视图对接的接口)
2.xml布局文件中
用
ActivityMainBinding.inflate()
获取系统自动生成的布局文件xml对象类(也就是xml布局文件与activity对接的接口)
最终:
private ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
获取了两者交融的产物binding,可以获取视图setContentView(binding.getRoot());
可以直接操作布局文件中的控件。
总结:就是两个文件分别给出一个交接的代表,然后二者绑定(交融)出了一个可以交互的产物。