msg:片段不支持数据绑定表达式(在标记<片段>中)数据绑定错误

时间:2019-03-02 08:31:26

标签: android data-binding android-databinding

当我尝试通过map添加标签片段的可见性时,数据绑定出现问题:

<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
                />

如何使用数据绑定解决此问题?为什么片段不支持数据绑定?

1 个答案:

答案 0 :(得分:0)

我可以像这样解决这个问题:

 <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>
相关问题