Android是否会重用从资源加载的图像? [英] Does android reuse images loaded from resource?

查看:62
本文介绍了Android是否会重用从资源加载的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在一个Activity中有多个ImageView,它们全部使用资源中的相同图像位图.

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);

android是否分配内存以一次加载位图,并使用同一资源将其重新用于所有其他ImageView?还是会每次加载位图并将其设置为ImageView?

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?

谢谢!

推荐答案

引用Android团队的Dianne Hackborn:

Quoting Dianne Hackborn from Android team:

还要记住,资源已经使用此功能为您维护了Drawable的缓存,因此您无需为从Resources中检索到的任何Drawable实施自己的缓存.

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.

来自此答案: drawable.setCallback(null)的结果;

这篇关于Android是否会重用从资源加载的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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