数据绑定必须包含布局文件

时间:2016-09-12 07:51:49

标签: android data-binding android-databinding

我遵循非常简单的布局,并希望切换到使用数据绑定。现在我的controller_main.xml

中出现了以下错误
Error:Execution failed for task ':app:dataBindingProcessLayoutsDebug_pro'.
  

**** /数据绑定错误****消息:[44 68 44 68 25]必须包含布局   文件:... \程序\ SRC \主\水库\布局\ controller_main.xml   **** \数据绑定错误****

有什么想法吗?错误说,android:layout标记中的资源include 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" />

2 个答案:

答案 0 :(得分:15)

您应该使用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"/>

答案 1 :(得分:0)

我有完全相同的错误,但是原因不同。 我使用<include>开头标签和</include>结束标签,而不是<include进行打开和/>进行关闭。有点奇怪,但是无论如何您的问题帮助我找到了我的错误。谢谢。

相关问题