Ram*_*eti 3 android android-databinding
我正在尝试使用数据绑定到我现有的项目。作为其中的一部分,最初我试图摆脱所有 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>
Run Code Online (Sandbox Code Playgroud)
将 android 绑定添加到此布局(将布局添加为父标签)后,它会抛出如下错误。
数据绑定不支持包含为合并元素的直接子元素
我遵循了android官方指南Android数据绑定。
我只是想摆脱上述布局文件的 findViewById 。
任何建议,将不胜感激。谢谢
您提供的链接显然表示不支持。
数据绑定不支持包含为合并元素的直接子元素。例如,不支持以下布局:
Run Code Online (Sandbox Code Playgroud)<?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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1947 次 |
| 最近记录: |