禁用某些布局的数据绑定

Disable data binding for some layouts

是否可以为某些布局禁用 Android 数据绑定?

dataBinding {
    enabled = true // not for all layout, possible ?
}

好吧,如果你不使用布局标签包装你的布局,你就不会使用它

如果您希望在生成绑定时忽略布局文件 类,请将 tools:viewBindingIgnore="true" 属性添加到该布局文件的根视图:

tools:viewBindingIgnore="true"

例如

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:viewBindingIgnore="true"
tools:context=".ui.MainActivity">