
如果图像已经缓存,我不想下载图像.我正在使用NOSTRA的ImageLoader库.请告诉我是否有办法做到这一点.以下是代码: –
displayImageOptions options = new displayImageOptions.Builder() .showStubImage(R.drawable.ic_stub) .showImageForEmptyUri(R.drawable.ic_sample) .resetVIEwBeforeLoading() .cacheInMemory() .cacheOndisc() .imageScaleType(ImageScaleType.EXACTLY_@R_396_4041@) .bitmapConfig(Bitmap.Config.ARGB_8888) .build(); imageLoader.displayImage(url2.toString() ,thumbnail,options, new ImageLoadingListener() { @OverrIDe public voID onl oadingStarted() { // progressbar.setVisibility(grID.VISIBLE); // grID.notify(); } @OverrIDe public voID onl oadingFailed(FailReason failReason) { //progressbar.setVisibility(grID.GONE); // grID.notify(); } @OverrIDe public voID onl oadingComplete(Bitmap bitmap) { // progressbar.setVisibility(grID.GONE); // grID.notify(); } @OverrIDe public voID onl oadingCancelled() { // progressbar.setVisibility(grID.GONE); //grID.notify(); } });解决方法:
您尚未在displayImageOption中定义默认缓存选项.
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) .threadPoolSize(5) .threadPriority(Thread.MIN_PRIORITY + 3) .denyCacheImageMultipleSizesInMemory() // 1MB=1048576 .memoryCacheSize(1048576 * 5) .discCache(new UnlimiteddiscCache(cacheDir)) .build();这里,cacheDir是一个目录可能在SD卡上(需要权限“androID.permission.WRITE_EXTERNAL_STORAGE”)
或应用程序的缓存目录.
我在我的应用程序中提供了cacheDirectory.
file cacheDir = new file(this.getCacheDir(), "name of directory"); if (!cacheDir.exists()) cacheDir.mkdir();现在,在下载任何图像之前,通过以下代码向ImageLoader提供配置,
imageLoader.init(config); 总结 以上是内存溢出为你收集整理的android – ImageLoader – 如果图像已经被缓存,请不要下载图像全部内容,希望文章能够帮你解决android – ImageLoader – 如果图像已经被缓存,请不要下载图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)