【发布时间】:2013-09-05 05:01:41
【问题描述】:
我正在使用 Universal-Image-Loader 来处理我的图像的显示,我正在使用类似 gridview 的实现来显示图像。在显示图像之前,它将首先下载并缓存到 sd 卡中。在图像仍在下载的同时,我使用每个图像的惰性列表实现来处理视图。
问题:
下载完所有图片并准备好展示后, 每次我滚动gridview时,图像都会在某种程度上再次使用惰性列表下载, 我相信它是从我的应用程序的缓存文件夹(SD 卡)中下载的。滚动时有什么方法可以保留图像(最终状态)?这样我每次滚动时都不需要下载它以获得平滑滚动。?我需要等到图像从 sd 卡完全加载,这样我才能平滑滚动。
我从 UIL 获得了这个设置,但我没有看到任何影响。
.resetViewBeforeLoading(false|true)
编辑
我也试过了,
imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(getActivity()));
下同
HttpParams params = new BasicHttpParams();
// Turn off stale checking. Our connections break all the time anyway,
// and it's not worth it to pay the penalty of checking every time.
HttpConnectionParams.setStaleCheckingEnabled(params, false);
// Default connection and socket timeout of 10 seconds. Tweak to taste.
HttpConnectionParams.setConnectionTimeout(params, 10 * 1000);
HttpConnectionParams.setSoTimeout(params, 10 * 1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);
ImageLoaderConfiguration config =
new ImageLoaderConfiguration
.Builder(getActivity())
.threadPoolSize(3)
.memoryCache(new WeakMemoryCache())
.imageDownloader(new HttpClientImageDownloader(getActivity(), new DefaultHttpClient(manager, params)))
.build();
imageLoader.init(config);
options = new DisplayImageOptions.Builder()
.showStubImage(icon)
.resetViewBeforeLoading(false)
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error)
.cacheInMemory(true)
.cacheOnDisc(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
我试过了,设置还是一样。
【问题讨论】:
-
你能发布你的UIL配置的完整代码吗?
-
试试看更新先生。
-
使用 androidquery 框架非常棒,它负责缓存管理和异步加载图像。在这里找到code.google.com/p/android-query
-
@BirajZalavadia 不确定这是否可以解决我在 scolling 时保留图像的问题,androidquery 我已经习惯了 UIL。
-
如果我理解正确,问题在于重新创建 gridView 的元素(
GridView像ListView不包含所有元素,但在它们变得可见时创建它们)。你可以编写你的适配器来保留所有元素并返回一个现有的而不是创建它)。
标签: java android caching universal-image-loader