nic*_*ich 3 data-binding android android-databinding
当我尝试使用地图为标记片段添加可见性时,我遇到了数据绑定问题:
<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
/>
Run Code Online (Sandbox Code Playgroud)
如何使用数据绑定解决这个问题?为什么片段不支持数据绑定?
我是这样解决这个问题的:
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1018 次 |
| 最近记录: |