数据绑定必须包含布局文件
databinding must include a layout file
我有以下非常简单的布局,想切换到使用数据绑定。现在我的 controller_main.xml
:
出现以下错误
Error:Execution failed for task ':app:dataBindingProcessLayoutsDebug_pro'.
****/ data binding error ****msg:[44 68 44 68 25] must include a layout
file:...\app\src\main\res\layout\controller_main.xml
****\ data binding error ****
有什么想法吗?错误说,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" />
你应该使用 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"/>
我遇到了完全相同的错误,但原因不同。
我使用 <include>
开始标签和 </include>
结束标签,而不是 <include
开始标签和 />
结束标签。这有点奇怪,但无论如何你的问题帮助我找到了我的错误。谢谢
我有以下非常简单的布局,想切换到使用数据绑定。现在我的 controller_main.xml
:
Error:Execution failed for task ':app:dataBindingProcessLayoutsDebug_pro'.
****/ data binding error ****msg:[44 68 44 68 25] must include a layout file:...\app\src\main\res\layout\controller_main.xml ****\ data binding error ****
有什么想法吗?错误说,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" />
你应该使用 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"/>
我遇到了完全相同的错误,但原因不同。
我使用 <include>
开始标签和 </include>
结束标签,而不是 <include
开始标签和 />
结束标签。这有点奇怪,但无论如何你的问题帮助我找到了我的错误。谢谢