msg:fragments不支持数据绑定表达式(in tag <fragment>)数据绑定错误
msg:fragments do not support data binding expressions (in tag <fragment>) data binding error
当我尝试使用地图为标签片段添加可见性时,我遇到了数据绑定问题:
<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
/>
如何使用数据绑定解决这个问题?为什么片段不支持数据绑定?
我是这样解决这个问题的:
<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>
当我尝试使用地图为标签片段添加可见性时,我遇到了数据绑定问题:
<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
/>
如何使用数据绑定解决这个问题?为什么片段不支持数据绑定?
我是这样解决这个问题的:
<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>