本文介绍了Android的效率 - 视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是更好地 findViewById(小于资源-ID>)键和存储在你的活动范围(类范围内的)或致电每次使用上面,因此,当目前的范围/方法退出该资源回收?

Is it better to findViewById(<resource-id>) once and store in the scope of your activity (class-wide) or call the above per use, so that the resources are reclaimed when the current scope/method is exited?

我猜它归结为如何昂贵 findViewById()进行比较,它是多么昂贵的存储视图对象类范围。

I guess it boils down to how expensive findViewById() is compared to how expensive it is to store view objects class-wide.

推荐答案

你只是要存储的参考意见;存储成本是最小的。最优质的code我见过找到视图每进行一次活动,所以我把它看作是最佳做法。可读性和可维护性只是奖金。

You're only storing references to views; the storage cost is minimal. Most quality code I've seen finds the view once for each activity, so I take that as best practice. Readability and maintainability are just bonuses.

这篇关于Android的效率 - 视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 04:20