简体   繁体   English

在ListView中存储和加载大量图像的最佳实践

[英]Best practice of storing and loading a lot of images in a ListView

My application has a ListView . 我的应用程序具有ListView The ListView has lots of images. ListView有很多图像。

1) What is the best/most efficient way to preload these images into my ListView ? 1)将这些图像预加载到ListView的最佳/最有效方法是什么? (I am setting the images in bindView() of SimpleCursorAdapter ). (我设置的图像bindView()SimpleCursorAdapter )。 Should I store them as assets, raw files or in the drawable directory? 我应该将它们存储为资产,原始文件还是可绘制目录中?

If I store my images in drawable , I basically have their name but not the int resource. 如果我将图像存储在drawable ,则基本上是它们的名称,但没有int资源。

2) Is getIdentifier() the way to go here? 2)是getIdentifier()去这里的方式吗?

The application queries the server if a new set of images are available. 该应用程序查询服务器是否有新的图像集。 If they are available it lazy downloads them and stores them into the cache. 如果它们可用,则懒惰地下载它们并将其存储到缓存中。 Now the old images are useless. 现在,旧图像已无用。

3) Is there any way to get rid of them? 3)有什么办法摆脱它们?

I suggest you to try Picasso .It takes care of handling cache and image loading. 我建议您尝试使用Picasso。它可以处理缓存和图像加载。

In the getView method of the Adapter class, all you need is one line of code. 在Adapter类的getView方法中,您只需要一行代码。

Picasso.with(context).load(image_url).into(holder.imageView);

What is the best/most efficient way to preload these images into my ListView? 将这些图像预加载到ListView中的最佳/最有效方法是什么?

You are already using LazyList so that's perfetct 您已经在使用LazyList,所以这是perfetct

 Should I store them as assets, raw files or in the drawable directory? 

That depends on your choice 那要看你的选择

Is there any way to get rid of them? 有什么办法摆脱它们?

yeah go to the FileCache class in lazylist,that in there there would be a variable cacheDir 是的,转到lazylist中的FileCache类,那里会有一个变量cacheDir

which actually tells you the directory where the older/cached images are stored and hence you can perform whatever you want to,from there 它实际上告诉您存储较旧/缓存图像的目录,因此您可以从那里执行任何操作

Edit: here is the link for lazylist https://github.com/thest1/LazyList 编辑:这是惰性列表的链接https://github.com/thest1/LazyList

what it does is,it downsamples the images before loading into the iamgeview hence saving a lot of memory,i guess it uses viewholder pattern and hence nothing to worry about memory leaks also it loads images asynchronously and hence UI doesn't lag for the time images are being loaded 它的作用是,它在加载到iamgeview之前先对图像进行下采样,从而节省了大量内存,我猜它使用了Viewholder模式,因此不必担心内存泄漏,而且它异步加载图像,因此UI不会滞后图像正在加载

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

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