【问题标题】:Android - UIL How to show loading image only when image has not cached?Android - UIL如何仅在图像未缓存时显示加载图像?
【发布时间】:2015-07-07 00:07:54
【问题描述】:

我正在使用通用图像库在 Android 中显示图像。

我知道在 DisplayImageOptions 中使用 showImageOnLoading(img_id) 允许 ImageView 在加载图像资源时显示正在加载的图像。

当我使用此选项从互联网上抓取图像时效果很好。 但是,它从缓存加载图像时效果不佳。它会立即显示加载图像,然后显示缓存图像。只是眨眼。

如果缓存图像存在,我不想眨眼,只显示缓存图像(没有加载图像)。

这是我使用的代码:

DisplayImageOptions options = new DisplayImageOptions.Builder()
        .showImageOnLoading(R.drawable.ic_launcher)
        .cacheOnDisk(true)
        .cacheInMemory(false)
        .imageScaleType(ImageScaleType.EXACTLY)
        .bitmapConfig(Bitmap.Config.RGB_565)
        .build();
String url = "http://i2.wp.com/www.fmxexpress.com/wp-content/uploads/2014/02/pullto.jpg";
ImageView image = (ImageView) findViewById(R.id.image);
ImageLoader.getInstance().displayImage(url, image, options);

我该怎么做?

【问题讨论】:

    标签: android image caching imageview universal-image-loader


    【解决方案1】:

    我认为闪烁是由从磁盘读取文件的过程引起的。 如果你只是像这样将图像缓存在内存中怎么办:

        .cacheOnDisk(false)
        .cacheInMemory(true)
    

    【讨论】:

    • 感谢您的回答,但我需要在磁盘上缓存许多图像,因此 cacheInMemory 不是一个选项。
    • 两个都打开怎么样?
    • 实际上,我不想缓存在内存中,因为内存对于某些内存不足的设备至关重要。
    猜你喜欢
    • 2014-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-06
    • 2012-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多