2017-11-27 1 views
0

안드로이드 스튜디오 3.0데이터 바인딩 : 특성은

classpath 'com.android.tools.build:gradle:3.0.1' 

내가 데이터 바인딩을 사용하려면

dataBinding { 
     enabled = true 
    } 

을 설정 Androld 네임 스페이스 접두사가 없습니다. 여기

내 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> 

하지만 얻을 오류 :

Attribute is missing the Android namespace prefix 

답변

4

귀하의 데이터 바인딩 XML 루트가되어야합니다 layout 태그

From Docs

Data-binding layout files are slightly differentstart with a root tag of layout followed by a data element 및 av 루트 요소를 봅니다. 이 뷰 요소는 루트가 비 바인딩 레이아웃 파일에있을 것입니다.

<?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>