我在我的项目中使用数据绑定,我有一个用于从视图模型设置可见性条件:
<View
app:visibilityCondition="@{viewModel.showingItems}" />
Run Code Online (Sandbox Code Playgroud)
这一切都很好,但是突然间我想在这样的包含标签上使用它时:
<include
layout="@layout/my_include_layout
app:visibilityCondition="@{viewModel.showingItems}" />
Run Code Online (Sandbox Code Playgroud)
它不会构建,并出现以下错误:
e: [kapt] 发生异常:android.databinding.tool.util.LoggedErrorException:发现数据绑定错误。在 com.example.CustomBinding 上找不到参数类型为 boolean 的属性“app:visibilityCondition”的设置器。
由于CustomBinding该类实际上并未从 扩展View,而是从 扩展ViewDataBinding,因此看起来我没有办法做到这一点。
有没有办法解决这个问题,还是我被迫以编程方式设置这个包含布局的可见性?我知道这会起作用,但如果可能的话,我真的很想将它保留在数据绑定中。