数据绑定不支持包含为合并元素的直接子元素
Data binding does not support include as a direct child of a merge element
我正在尝试对现有项目使用数据绑定。作为其中的一部分,最初我试图摆脱所有 findViewById() 方法。
现在的问题是,我的布局如下:-
<merge >
<include
android:id="@+id/my_login_process_view"
layout="@layout/content_my_message_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</merge>
将 android 绑定添加到此布局(将布局添加为父标记)后,它会抛出如下错误。
数据绑定不支持作为合并元素的直接子项包含在内
我已遵循 android 官方指南 Android data binding。
我只是想摆脱上面布局文件的 findViewById。
如有任何建议,我们将不胜感激。谢谢
你提供的link明明说不支持
Data binding does not support include as a direct child of a merge
element. For example, the following layout is not supported:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable name="user" type="com.example.User"/>
</data>
<merge>
<include layout="@layout/name"
bind:user="@{user}"/>
<include layout="@layout/contact"
bind:user="@{user}"/>
</merge>
</layout>
根据官方文档,它的工作原理是下面的代码
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable name="user" type="com.example.User"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/name"
bind:user="@{user}"/>
<include layout="@layout/contact"
bind:user="@{user}"/>
</LinearLayout>
</layout>
我正在尝试对现有项目使用数据绑定。作为其中的一部分,最初我试图摆脱所有 findViewById() 方法。
现在的问题是,我的布局如下:-
<merge >
<include
android:id="@+id/my_login_process_view"
layout="@layout/content_my_message_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</merge>
将 android 绑定添加到此布局(将布局添加为父标记)后,它会抛出如下错误。
数据绑定不支持作为合并元素的直接子项包含在内
我已遵循 android 官方指南 Android data binding。
我只是想摆脱上面布局文件的 findViewById。
如有任何建议,我们将不胜感激。谢谢
你提供的link明明说不支持
Data binding does not support include as a direct child of a merge element. For example, the following layout is not supported:
<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:bind="http://schemas.android.com/apk/res-auto"> <data> <variable name="user" type="com.example.User"/> </data> <merge> <include layout="@layout/name" bind:user="@{user}"/> <include layout="@layout/contact" bind:user="@{user}"/> </merge> </layout>
根据官方文档,它的工作原理是下面的代码
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable name="user" type="com.example.User"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/name"
bind:user="@{user}"/>
<include layout="@layout/contact"
bind:user="@{user}"/>
</LinearLayout>
</layout>