【问题标题】:Imageview has no image when load at first time using Glide使用 Glide 首次加载时 Imageview 没有图像
【发布时间】:2019-09-08 10:22:07
【问题描述】:

我正在使用Glide v4 加载我的图片,但我的应用遇到了错误:

I/Glide: Root cause (1 of 1) com.bumptech.glide.load.HttpException: Not Found
    at com.bumptech.glide.integration.okhttp3.OkHttpStreamFetcher.onResponse(OkHttpStreamFetcher.java:73)
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:206)
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:764)

第一次加载时会发生这种情况,但是当我再次重新加载时,图像现在出现了。

我正在从我的RecyclerView 适配器加载图像,例如:

class MyRecyclerViewAdapter(private val glideApp: GlideRequests): RecyclerView.Adapter<MyRecyclerViewAdapter.ViewHolder>() {
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        //... some stuff
        // Set a data
        glideApp.asBitmap()
            .load(img_url)
            .into(holder.itemView.ivImageHolder)
        // Set a data
    }
}

感谢您的帮助。

【问题讨论】:

  • 你找到解决办法了吗?

标签: android android-recyclerview android-glide httpexception


【解决方案1】:

试试这个,

私有列表 myUrls = ...;

@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
  ImageView imageView = ((MyViewHolder) viewHolder).imageView;
  String currentUrl = myUrls.get(position);

  Glide.with(fragment)
    .load(currentUrl)
    .override(imageWidthPixels, imageHeightPixels)
    .into(imageView);
}

check this also

【讨论】:

    【解决方案2】:
    Glide.with(context)
        .load(img_url)
        .asBitmap()
        .into(holder.itemView.ivImageHolder);
    

    “context”包含传递给适配器的活动或片段的实例

    【讨论】:

      【解决方案3】:

      我通过更改 ImageView 属性解决了这个问题。

      android:width:"wrap_content" 更改为android:width:"match_parent"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-05-09
        • 2017-12-17
        • 1970-01-01
        • 1970-01-01
        • 2015-10-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多