在XML布局文件加载是否缓存Android的绘图资源? [英] Does Android cache drawable resources loaded in xml layout files?
问题描述
我有一个 ViewPager
,加载大量片段(+20)的。这些片段中的每一个仅仅是一个单一片段的一个实例,并且改变的唯一事情是每一个的内容。这个片段的UI了,其他部件中,4种不同的 ImageViews
所有加载相同的资源绘制,但当然是位于用户界面的不同部分。
I have a ViewPager
which loads lots of fragments (+20). Each one of these fragments is just an instance of one single fragment, and the only thing that changes is the content of each one. The UI for this fragment has, among other widgets, 4 different ImageViews
which all load the same resource drawable but are of course located in different parts of the UI.
现在,如果我们考虑到,我可能有例如20个片段与此计划的帐户,我们在谈论80(20 * 4)ImageViews这将全部加载相同的绘制。
Now, if we take into account that I might have for example 20 fragments with this scheme, we're talking about 80 (20*4) ImageViews which would all load the same drawable.
所以,这使我想知道,是否在从XML布局加载任何资源的Android缓存?如果没有,是否有更好的选择,然后只需每到这个片段的一个新实例被创建时加载这个可绘制在code,缓存,并编程它连接到其对应的ImageView?
So, that made me wonder, does Android cache in any way resources that are loaded from xml layouts? If not, is there a better option then simply loading this drawable in code, caching it and attaching it programmatically to their corresponding ImageView every time a new instance of this fragment gets created?
感谢。
推荐答案
的Android确实有某种形式的回收利用管理与可绘制
组件。我一直在使用时可绘制
相同的资源,并使用 ColorFilter
与他们注意到了这一点很清楚,我已经结束看到错误色彩搭配previously创建绘制它一直没有可见但在UI。
Android does have some kind of recycling management with Drawable
component. I have noticed this very clear when using same resources for Drawables
and using ColorFilter
with them, and I have ended seeing wrong color with previously created drawable which hasn't been visible yet in UI.
我会说你的方法就可以了。
I would say your approach is OK.
在这篇文章罗曼解释说,可绘制
分享一些信息,例如位图
他们正在绘制:<一HREF =http://www.curious-creature.org/category/android/page/2/相对=nofollow> http://www.curious-creature.org/category/android/page/2/
In this post Romain explains that Drawables
share some information, for example the Bitmap
they are drawing: http://www.curious-creature.org/category/android/page/2/
这篇关于在XML布局文件加载是否缓存Android的绘图资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!