Android数据绑定与findViewById的性能 [英] Android data binding vs findViewById for performance

查看:212
本文介绍了Android数据绑定与findViewById的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到MVVM的Android数据绑定的潜力很大,它打开了门。但是关于性能,数据绑定速度更快,然后在本机android中使用findViewById?

解决方案

看起来, 文档



视图带ID


将为每个视图生成一个公共final字段
布局中的ID。绑定在View层次结构上执行单次传递,
使用ID提取视图。这个机制可以比
调用几个视图的findViewById更快。


所以似乎数据绑定只需要做一个传递视图层次结构而不是我们总是调用findViewById。


I realize the potential for android data binding for MVVM is great and it opens doors. But regarding performance, is data binding faster then using findViewById in native android ?

解决方案

It looks to me that it is faster per the docs:

Views With IDs

A public final field will be generated for each View with an ID in the layout. The binding does a single pass on the View hierarchy, extracting the Views with IDs. This mechanism can be faster than calling findViewById for several Views.

So it seems data binding only has to do a single pass over the view hierarchy instead of us always calling findViewById.

这篇关于Android数据绑定与findViewById的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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