首页 > 解决方案 > Redmi note 4 不显示缓存滑行中的图像

问题描述

我正在使用带有磁盘缓存的 Glide 4.1.1 加载图像,它在 Red Mi note 4 以外的其他设备上运行良好。Red Mi note 4 没有显示任何缓存图像。而我的模拟器和 Micromax android 则完美地显示了缓存的图像。

 Glide.with(context)
            .load(stringUrl).apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.RESOURCE))
            .listener(new RequestListener<Drawable>() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                    viewHolderListener.onLoadCompleted(image, adapterPosition);
                    return false;
                }

                @Override
                public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                    L.d(loadedData.get(adapterPosition).getImagePath());
                    viewHolderListener.onLoadCompleted(image, adapterPosition);
                    return false;
                }
            })
            .into(image);

标签: androidandroid-glide

解决方案


尝试将 glide 库更新到新版本

    dependencies {
  implementation ("com.github.bumptech.glide:glide:4.9.0") {
    exclude group: "com.android.support"
  }

最重要的是你必须在你的应用程序中包含 AppGlide 模块

package com.example.myapp;

import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

@GlideModule
public final class MyAppGlideModule extends AppGlideModule {}

最后,您可以通过编写以下代码来启用缓存:

GlideApp.with(fragment)
  .load(url)
  .diskCacheStrategy(DiskCacheStrategy.ALL)
  .into(imageView);

参考:GlideV4 文档


推荐阅读