小编lut*_*riz的帖子

Android 数据绑定包括来自不同模块的布局

我的项目中有多个模块,假设模块 app 和模块 A 充当模块 app 的库。我使用数据绑定并通过添加正常工作

dataBinding { enabled = true }

在每个模块 build.gradle 中。

当我使用标签从模块 A 包含布局时出现问题。当我尝试访问包含布局的数据绑定时,它返回 View 对象而不是 ViewDataBinding

Android Studio 自动完成

但是,当我尝试继续访问包含布局中的 id 时,即使 IDE 显示错误,编译也能正常工作。我试过重建项目,使缓存和其他一切无效。

android studio 上的错误

而且我确信已经遵循了如何实现 DataBinding 的规则。这是模块应用程序的布局:

<layout xmlns:android="http://schemas.android.com/apk/res/android>
    <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:background="@color/light_gray"
       android:orientation="vertical">

        <include layout="@layout/included_layout" id="@+id/contact"/>
    </LinearLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)

以及模块 A 上的布局:

<layout xmlns:android="http://schemas.android.com/apk/res/android>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)

data-binding android android-studio

6
推荐指数
1
解决办法
1291
查看次数

标签 统计

android ×1

android-studio ×1

data-binding ×1