V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
andev
V2EX  ›  Android

Glide 加载图片失败重新加载的问题

  •  
  •   andev · Aug 13, 2020 · 12977 views
    This topic created in 2084 days ago, the information mentioned may be changed or developed.
    RecycleView 里的列表图片用 Glide 加载,使用 new RequestOptions().error(R.drawable.bg)加载失败占位。
    在 onBindViewHolder 里使用 Glide 加载图片失败,占位图显示。
    这时,只要稍微滑动一下 RecycleView,显示区域内之前失败的图片又会重新请求网络加载(没有滑动到新的 Item,onBindViewHolder 没有调用)。
    这是为什么? RecycleView 滑动怎么触发 Glide 加载之前失败的 URL 图片?
    2 replies    2020-08-13 16:18:58 +08:00
    Tenma
        1
    Tenma  
    PRO
       Aug 13, 2020
    开启缓存?
    andev
        2
    andev  
    OP
       Aug 13, 2020
    找到原因了,在 RecyleView 滑动监听里处理了 Glide:
    if (newState == RecyclerView.SCROLL_STATE_IDLE) {
    Glide.with(getContext()).resumeRequests();
    }

    导致在滑动停止时,Glide 调用 resumeRequests 重新请求了之前失败的 URL,Glide 有什么方法调用使得在请求失败后,
    不将失败的请求保存之后再请求?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5880 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 06:10 · PVG 14:10 · LAX 23:10 · JFK 02:10
    ♥ Do have faith in what you're doing.