Android:DataBinding和ViewBinding之间的区别 [英] Android : Difference between DataBinding and ViewBinding

查看:680
本文介绍了Android:DataBinding和ViewBinding之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自Jetpack发行以来,我们一直在使用 DataBinding 。 Android文档指示 Android Studio 3.6 Canary 11+中已添加 ViewBinding



我是真实的文档,但看起来与 DataBinding类似。



有人可以解释我们如何区别这两个概念吗?

解决方案

根据官方文档


ViewBinding


仅将视图绑定到代码。


DataBinding


将数据(从代码)绑定到视图+ ViewBinding(将视图绑定到代码)



有三个重要区别


  1. 使用视图绑定时,布局不需要布局标签



  2. 您不能使用viewbinding将布局与xml
    中的数据绑定(没有绑定表达式,无绑定


  3. 视图绑定的主要优点是速度和效率。它具有较短的构建时间,因为它避免了由于注释处理器影响数据绑定的构建时间而导致的与数据绑定相关的开销和性能问题。



简而言之,没有任何视图绑定可以做数据绑定不能做的事情(尽管以更长的构建时间为代价),并且有很多数据绑定可以做的视图绑定不能 t


We are using DataBinding since Jetpack release. Android documentation indicates that ViewBinding was added in Android Studio 3.6 Canary 11+.

I real documentation but its looks likes similar with DataBinding.

Can anyone explain how we can differ this two concepts?

解决方案

According to the official docs:

ViewBinding

Only binding views to code.

DataBinding

Binding data (from code) to views + ViewBinding (Binding views to code)

There are three important differences

  1. With view binding, the layouts do not need a layout tag

  2. You can't use viewbinding to bind layouts with data in xml (No binding expressions, no BindingAdapters nor two-way binding with viewbinding)

  3. The main advantages of viewbinding are speed and efficiency. It has a shorter build time because it avoids the overhead and performance issues associated with databinding due to annotation processors affecting databinding's build time.

In short, there is nothing viewbinding can do that databinding cannot do (though at cost of longer build times) and there are a lot databinding can do that viewbinding can"t

这篇关于Android:DataBinding和ViewBinding之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆