使用通用图像装载机在GridView控件加载图片 [英] Loading images in GridView using Universal Image Loader

查看:152
本文介绍了使用通用图像装载机在GridView控件加载图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是通用图像装载机1.8.6 库加载从网络采取dinamically图片

I'm using the Universal Image Loader 1.8.6 library for loading dinamically images taken from web.

ImageLoaderConfiguration 配置如下:

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
    .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
    .threadPoolSize(3) // default
    .threadPriority(Thread.NORM_PRIORITY - 1) // default
    .denyCacheImageMultipleSizesInMemory()
    .memoryCacheSize(2 * 1024 * 1024)
    .memoryCacheSizePercentage(13) // default
    .discCacheSize(50 * 1024 * 1024)
    .discCacheFileCount(100)
    .imageDownloader(new BaseImageDownloader(getApplicationContext())) // default
    .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
    .writeDebugLogs()
    .build();

DisplayImageOptions 配置为:

DisplayImageOptions options = new DisplayImageOptions.Builder()
    .showStubImage(R.drawable.no_foto)
    .showImageForEmptyUri(R.drawable.no_foto)
    .showImageOnFail(R.drawable.no_foto)
    .build();

我ArrayAdapter内的方法getView包含code:

The method getView inside my ArrayAdapter contains the code:

iv.setImageResource(R.drawable.no_foto); 
imageLoader.displayImage(basePath+immagine, iv);

以上code中的第一行用于只是为了避免这种情况的看法在GridView中回收允许设置错了位置的图像(直到画面尚未下载)。

The first line of the above code is used just for avoid that the recycling of view in gridView allow to set image in the wrong position (until the picture has not been downloaded).

实际的问题是这样的:

如果我打开我的活动(包含的GridView )的显示项目感谢UIL库可下载图像。 (同时, no_foto.png 图像显示在网格的每个视图)。当所有的意见都装入自己的形象,如果我尝试向下滚动,然后我回来了(滚动起来)我要等的图像重新加载,因为所有的意见是由现在占领了 no_foto.png 图像。

If I open my Activity (containing the GridView) the shown items thanks to the UIL library can download the image. (Meanwhile the no_foto.png image is shown in each view of the grid). When all the views have loaded their own images, if I try to scroll down and then I come back (scrolling up) I have to wait that the images are reloaded, because all the views are now occupied by the no_foto.png image.

我怎样才能避免这些图像的重载?使用通用图像装载机,我可以缓存图像previous装?

How can I avoid the reload of these images? Using Universal Image Loader, can I cache the images previous loaded?

注意:由于我的网格可以包含多个图片我会使用磁盘缓存(而不是内存缓存)的实现。 我发现, .discCacheFileCount()可用于设置缓存文件的最大数,那么为什么它看来,我的文件都不会被缓存?

NOTE: Since my grid can contain many images I would to use an implementation of disk cache (not memory cache). I found that .discCacheFileCount() can be used for setting the maximum number of cached files, so why it seems that my files are not cached?

推荐答案

我已经解决了这个问题。

I have solved the problem

我刚刚宣布的选择,但我wans't使用它,所以我已经修改了行:

I was just declaring option, but I wans't using it, so I have modified the line:

imageLoader.displayImage(basePath+immagine, iv);

imageLoader.displayImage(basePath+immagine, iv, options);

和我在选项中添加的方法:

and I have added in the options the method:

.cacheOnDisc(true)

这篇关于使用通用图像装载机在GridView控件加载图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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