数据绑定布局奇怪的生成错误



在我的项目中,我有Android数据绑定库v.2.3.3

添加新的 aar 库依赖项后,我在使用消息编译项目时出现错误

/Users/.../app/build/intermediates/data-binding-layout- 
out/.../debug/layout/..-activity.xml:90: error: Error: No resource found 
that matches the given name (at 'layout_above' with value 
'@id/buttonLayout').

我已经检查了构建/中间体中的xml,看起来还不错:

...
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainLayout"
android:layout_above="@id/buttonLayout">
...
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/_button_size"
android:layout_alignParentBottom="true"
android:id="@+id/buttonLayout">
...
</RelativeLayout>   
...

什么可能导致问题?它与数据绑定有关吗?
我尝试使用aar库其他项目,它正在工作

在您的mainLayout中,您引用的 ID@id/buttonLayout尚未添加到资源中,因为它在下面的第二个RelativeLayout中声明。要解决此问题,您需要先使用如下所示@+id添加它:

...
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainLayout"
android:layout_above="@+id/buttonLayout">
...
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/_button_size"
android:layout_alignParentBottom="true"
android:id="@id/buttonLayout">
...
</RelativeLayout>   
...

最新更新