一般在安卓中最常用的inflate方法为
public View inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot)
这三个参数的意义如下图所示
我在使用recyclerView时,在adapter的onCreateViewHolder方法中写的是
ItemBinding binding = ItemBinding.inflate(LayoutInflater.from(parent.getContext()));
运行时item的布局宽度出现了问题,改为
ItemBinding binding = ItemBinding.inflate(LayoutInflater.from(parent.getContext()),parent,false);
后恢复正常,就对应上图描述的“当root为null时,被加载的布局的LayoutParams会被改变”。