【问题标题】:Android <include> didn't work with ViewBindingAndroid <include> 不适用于 ViewBinding
【发布时间】:2020-03-25 22:18:05
【问题描述】:

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

包含文件只是一个基本的布局文件。如果我将 &lt;include&gt; 标记直接替换为应包含的布局代码,一切正常。

这是生成的类的异常:

error: incompatible types: TeaserAgreementBinding cannot be converted to ViewDataBinding
        setContainedBinding(this.mboundView11);

有什么建议吗?

谢谢, 米尔科

【问题讨论】:

    标签: android android-viewbinding


    【解决方案1】:

    您还必须使用布局标签包装您的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>
    

    【讨论】:

      猜你喜欢
      • 2021-06-26
      • 2016-11-13
      • 2017-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      • 2014-09-29
      相关资源
      最近更新 更多