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标记
Data-binding layout files are slightly different和start 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)
| 归档时间: |
|
| 查看次数: |
2288 次 |
| 最近记录: |