当我尝试使用 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/