我正在阅读MVVM体系 struct 的工作原理以及如何使用Android数据绑定库帮助.

一般来说,我理解Android数据绑定在UI层和底层数据模型之间创建了一个链接,该模型保存了要显示的信息.

Kotlin Android扩展是另一个Kotlin插件,可以让你从活动、片段和视图中恢复视图.该插件将生成一些额外的代码,允许您访问XML布局中的视图,就像它们是具有您在布局定义中使用的id名称的属性一样.

使用Android数据绑定库和Kotlin Android扩展有什么不同?它们是出于不同的目的吗?它们在哪些方面是相辅相成的呢?

Thank you for your answers.

推荐答案

Kotlin Android扩展和Android数据绑定库都有助于消除findViewById的使用.

But there are also more things that these do, that can complement one another. To elaborate, with the Android Data Binding library, you can 'set' models in your xml files, which can then directly be leveraged to set values for the views in the layout. See how a <data> tag can be used with the data binding library.

Kotlin android扩展没有提供这种功能.

To conclude, while they both eliminate the use of findViewById, they have their own features too which can complement one another well.

Kotlin相关问答推荐

在Kotlin 有更好的结合方式?

Kotlin多平台(KMP)保存到文件不能在iOS上保存

Kotlin 说不需要强制转换,但删除后会出现新警告

限制通用Kotlin枚举为特定类型

在 map 中查找键与在 kotlin 中查找 firstOrNull

如何处理基于枚举提前返回的 forEach 循环,Kotlin 中的一条路径除外

Kotlin - 创建指定长度的随机整数的 ArrayList?

如何在 kotlin @Parcelize 中使用 null

Kotlin - 当表达式返回函数类型

如何退出 Kotlinc 命令行编译器

如何从定义它们的类外部调用扩展方法?

Foo::class.java 和 Foo::javaClass 有什么区别?

作为 Kotlin 中的函数的结果,如何从 Firestore 数据库返回列表?

Firebase 权限被拒绝

如何在MVVM架构中观察RecyclerView适配器中的LiveData?

无法在Kotlin中使用argb color int值?

Kotlin中具有多个参数的绑定适配器

Android:Exoplayer - ExtractorMediaSource 已弃用

如何在Kotlin中将字符串转换为InputStream?

RxJava - 每秒发出一个 observable