Android <include> 不适用于 ViewBinding

Mir*_*rco 2 android android-viewbinding

我对这个“新”Android 视图绑定有疑问。<include> 当我尝试在 XML 布局文件中 使用 a 时,出现异常 :<include layout="@layout/teaser_agreement" />

包含文件只是一个基本的布局文件。<include>如果我直接用应该包含的布局代码替换标签,一切都会正常。

这是生成的类的异常:

error: incompatible types: TeaserAgreementBinding cannot be converted to ViewDataBinding
        setContainedBinding(this.mboundView11);
Run Code Online (Sandbox Code Playgroud)

有什么建议么?

谢谢,米尔科

Ali*_*ain 5

您还必须用teaser_agreement.xml布局标签包裹您的布局。所以它会是这样的:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

<--!Rest of your xml code-->
......
..........
............

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