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

pro*_*m85 7 data-binding android android-databinding

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

Error:Execution failed for task ':app:dataBindingProcessLayoutsDebug_pro'.
Run Code Online (Sandbox Code Playgroud)

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

有任何想法吗?错误说,标签中的资源android:layoutID include丢失(这是我对错误的解释),但事实并非如此.注释掉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>
Run Code Online (Sandbox Code Playgroud)

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" />
Run Code Online (Sandbox Code Playgroud)

Geo*_*unt 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"/>
Run Code Online (Sandbox Code Playgroud)

  • 已经发现了;-)谢谢。是从使用`ViewStubs` 改变为包含多个布局的东西... (2认同)