android - 消息 :fragments do not support data binding expressions (in tag <fragment>) data binding error

标签 android data-binding android-databinding

当我尝试使用 map 为标记 fragment 添加可见性时,我遇到了数据绑定(bind)问题:

<layout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        >
    <data>
        <import type="android.view.View"/>
        <import type="xxx.xxx.MapContract.ViewModel"/>
        <variable
                name="vm"
                type="ViewModel"
                />
    </data>
    <FrameLayout
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            >
        <fragment
                android:id="@+id/map_fragment"
                class="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:visibility="@{vm.showMap}" // here problem
                />

如何使用数据绑定(bind)解决这个问题?为什么 fragment 不支持数据绑定(bind)?

最佳答案

我是这样解决这个问题的:

 <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:visibility="@{!vm.showMap}" // move here
            >
        <fragment
                android:id="@+id/map_fragment"
                class="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                />
    </FrameLayout>

关于android - 消息 :fragments do not support data binding expressions (in tag <fragment>) data binding error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54956645/

相关文章:

android - 具有数据绑定(bind)的 ViewPager 项的位置

android - 如何让数据绑定(bind)表达式对同一布局中 EditText 的更改使用react?

android - 我需要遵循哪些步骤才能在我的 Android 手机上编写和编辑 python 程序?

java - 如何在android中延迟后显示按钮文本

Android:由于位图,HONEYCOMB 之前和之后的堆使用情况?

Android 管理不同屏幕上的 View 大小

javascript - Enter() 和 exit() 如何检测 D3 中的更新数据?

javascript - Vuejs 子组件中的 Prop 值无法绑定(bind)到元素属性

android - 如果绑定(bind)适配器提供 getter,请检查适配器是否正确注释以及参数类型是否匹配

android - 我如何在 android 数据绑定(bind)中绑定(bind)和调用`function type`?