Does android reuse images loaded from resource?

空扰寡人 提交于 2020-01-24 04:09:47

问题


So I have several ImageViews in a single Activity and all of them use the same image bitmap from a resource.

ImageViewOne.setImageResource(R.drawable.frequently_used_image);
ImageViewTwo.setImageResource(R.drawable.frequently_used_image);
ImageViewThree.setImageResource(R.drawable.frequently_used_image);

Does android allocate memory to load the bitmap once and reuse it for all other ImageViews using the same resource? Or does it load the bitmap each time it is set to an ImageView?

Thanks!


回答1:


Quoting Dianne Hackborn from Android team:

Also keep in mind that Resources already maintains a cache of Drawables for you, using this facility, so there is no need for you to implement your own cache for any Drawables you are retrieving from Resources.

from this answer: Consequences of drawable.setCallback(null);



来源:https://stackoverflow.com/questions/17098755/does-android-reuse-images-loaded-from-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!