数据绑定:属性缺少Androld名称空间前缀

Ale*_*lex 9 android

Android Studio 3.0

classpath 'com.android.tools.build:gradle:3.0.1'
Run Code Online (Sandbox Code Playgroud)

  dataBinding {
        enabled = true
    }
Run Code Online (Sandbox Code Playgroud)

我想使用数据绑定.

这是我的xml布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <data>
        <variable
            name="offer"  type="com.myproject.customer.Offer" />
    </data>

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

但我得到错误:

Attribute is missing the Android namespace prefix
Run Code Online (Sandbox Code Playgroud)

Pav*_*ngh 22

您的数据绑定XML根应该是layout标记

来自Docs

Data-binding layout files are slightly differentstart with a root tag of layout followed by a data element视图根元素.此视图元素是您的根在非绑定布局文件中的位置.

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
   <data>
       <variable name="user" type="com.example.User"/>
   </data>

  <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

  </android.support.constraint.ConstraintLayout>

</layout>
Run Code Online (Sandbox Code Playgroud)