【问题标题】:databinding must include a layout file数据绑定必须包含布局文件
【发布时间】:2017-01-19 14:46:07
【问题描述】:

我有以下非常简单的布局,并想切换到使用数据绑定。现在我的controller_main.xml 出现以下错误:

Error:Execution failed for task ':app:dataBindingProcessLayoutsDebug_pro'.

****/ 数据绑定错误 ****msg:[44 68 44 68 25] 必须包含布局 文件:...\app\src\main\res\layout\controller_main.xml ****\数据绑定错误****

有什么想法吗?错误说,include 标签中的资源android:layout id 丢失(这是我对错误的解释),但事实并非如此。注释掉 include 标记可以消除错误。

有人发现问题了吗?

controller_main.xml

<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" >

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinatorLayout"
        android:fitsSystemWindows="true"
        android:background="?attr/main_background_color"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <RelativeLayout
            android:id="@+id/rlContent"
            android:fitsSystemWindows="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </RelativeLayout>

        <include
            android:layout_width="fill_parent"
            android:layout_height="@dimen/tool_bar_top_padding"
            android:id="@+id/stub_view_main_header_fixed"
            android:layout="@layout/view_main_header_fixed"
            app:elevation="0dp"/>

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

        </android.support.design.widget.AppBarLayout>

    </android.support.design.widget.CoordinatorLayout>

</layout>

view_main_header_fixed.xml

<?xml version="1.0" encoding="utf-8"?>
<View
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/vStatusbarBackground"
    android:layout_width="match_parent"
    android:layout_height="@dimen/tool_bar_top_padding" />

【问题讨论】:

  • "id in the include tag is missing",这有什么不清楚的地方?
  • 你看到包含了吗?它正在定义一个id。而且我不知道你从哪里得到"id in the include tag is missing"...它说布局丢失。但是布局也被定义了。反正问题已经解决了……

标签: android data-binding android-databinding


【解决方案1】:

您应该使用layout 而不是android:layout:

<include
        android:layout_width="fill_parent"
        android:layout_height="@dimen/tool_bar_top_padding"
        android:id="@+id/stub_view_main_header_fixed"
        layout="@layout/view_main_header_fixed"
        app:elevation="0dp"/>

【讨论】:

  • 已经发现了 ;-) 谢谢。是不是从使用 ViewStubs 更改为包含包含的多个布局...
【解决方案2】:

我遇到了完全相同的错误,但原因不同。 我使用&lt;include&gt; 开始标签和&lt;/include&gt; 结束标签而不是&lt;include 用于打开和/&gt; 用于关闭。这有点奇怪,但无论如何你的问题帮助我找到了我的错误。谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-21
    • 2016-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多