最近跳槽的项目里,卧槽,居然用了DataBinding,搞了2h 没编译通过,what a fuck!!!
老是编译报错哦!
Error parsing XML: duplicate attribute
举例如下:
<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" // 问题项 xmlns:tools="http://schemas.android.com/tools" // 问题项 android:layout_width="match_parent" android:layout_height="45dp"> </RelativeLayout> </layout>
修改为:
<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <RelativeLayout android:layout_width="match_parent" android:layout_height="45dp"> </RelativeLayout> </layout>
问题解决
归纳如下:
1. DataBinding XML 根节点需用layout 标签;
2. DataBinding XML 中需要注意layout_width和layout_height 不要重复;
3. DataBinding XML include 不支持递归匹配找到id,需要注意一下(网上说的,待验证);
4. DataBinding XML 写法中注意一下xmlns 防止重复,否则解析失败;