简体   繁体   English

第一次使用 Glide 加载时 Imageview 没有图像

[英]Imageview has no image when load at first time using Glide

I'm using the Glide v4 to load my images, and my app is encountering an error:我正在使用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)

at first load this is what happen, but when I reload again the image is now appearing.第一次加载时会发生这种情况,但是当我再次重新加载时,图像现在出现了。

I am loading an image from my RecyclerView adapter like:我正在从我的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
    }
}

Any help is appreciated, Thanks.感谢您的帮助,谢谢。

Try this,试试这个,

private List myUrls =...;私有列表 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 也检查一下

Glide.with(context)
    .load(img_url)
    .asBitmap()
    .into(holder.itemView.ivImageHolder);

"context" contain the instance fo the activity or fragment which is passed on to the adapter “上下文”包含传递给适配器的活动或片段的实例

I solved the problem by changing ImageView attribute.我通过更改ImageView属性解决了这个问题。

Changed the android:width:"wrap_content" to android:width:"match_parent" .android:width:"wrap_content"更改为android:width:"match_parent"

Just set zoom post loading the image solved the issue只需设置缩放后加载图像即可解决问题

ivImageHolder.setZoom(0.99f)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM