在使用Android视图绑定时,可能需要根据某些条件动态地膨胀视图。下面是一种解决方法,其中包含代码示例:
android {
...
viewBinding {
enabled = true
}
}
public class ConditionInflater {
public static T inflate(
LayoutInflater inflater, ViewGroup parent, int layoutId, boolean isExtraVisible) {
String layoutName = inflater.getContext().getResources().getResourceEntryName(layoutId);
ViewDataBinding binding = DataBindingUtil.inflate(inflater, layoutId, parent, false);