简体   繁体   English

Android可绘制图像缓存

[英]Android Drawable Image Caching

If my application is showing a ListView and the ListView has ListViewItem that shows few pieces of info including images, are these images cached? 如果我的应用程序显示的是ListView,而ListView的ListViewItem显示的信息很少,包括图像,是否缓存了这些图像?

In other words, If my ListView shows 1000 items and each item has one image in a layout like below and that image is located in my Resources/drawable, will the image be loaded 1000 times ( and therefore consume 1000 x image_size of memory ) or will it be cached and loaded only once for all 1000 images ( and therefore consume only 1 x image_size of memory )? 换句话说,如果ListView显示1000个项目,并且每个项目在下面的布局中都有一个图像,并且该图像位于我的资源/可绘制对象中,则该图像将被加载1000次( 因此消耗了1000 x image_size的内存 ),或者是否会为所有1000张图像仅缓存和加载一次( 因此仅消耗1 x image_size的内存 )?

+--------------------------------------------------+
|           |             TEXT                     |             
|   IMAGE   |--------------------------------------|
|           |             TEXT          |  TEXT    |
+--------------------------------------------------+

If my application is showing a ListView and the ListView has ListViewItem that shows few pieces of info including images, are these images cached? 如果我的应用程序显示的是ListView,而ListView的ListViewItem显示的信息很少,包括图像,是否缓存了这些图像?

Every time you load an image and display it in an item (the item should be visible), it will consume 1 x image_size of memory, when you display 10 item in screen, it will consume 10 x image_size of memory, but when you have 1000 item item to display, that's another case. 每次加载图像并将其显示在一个项目中(该项目应该可见)时,它将消耗1 x image_size的内存,当您在屏幕上显示10个项目时,它将消耗10 x image_size的内存,但是当您有要显示的1000个项目,这是另一种情况。 If you just display these image and didn't use any ImageLoader logic, it will coasts a lot of memory and as a result, if will result in OOM . 如果仅显示这些图像,并且不使用任何ImageLoader逻辑,则它将占用大量内存,结果将导致OOM

You should write own ImageLoader logic, or just use libraries that have been around for some time that have almost perfected this. 您应该编写自己的ImageLoader逻辑,或者只使用已经存在一段时间的库,而这些库几乎可以完善它。 For example you could use Picasso : 例如,您可以使用Picasso

Many common pitfalls of image loading on Android are handled automatically by Picasso: 毕加索会自动处理Android上许多常见的图片加载陷阱:

  • Handling ImageView recycling and download cancelation in an adapter. 在适配器中处理ImageView回收和下载取消。

  • Complex image transformations with minimal memory use. 复杂的图像转换,使用最少的内存。

  • Automatic memory and disk caching. 自动内存和磁盘缓存。

Since it's a java lib, you can use Binding Library to use it in Xamarin. 由于它是一个Java库,因此您可以使用绑定库在Xamarin中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM