Glide not loading real image and stuck with placeholder

后端 未结 11 731
长情又很酷
长情又很酷 2021-02-02 05:59

I have a pretty basic load image from server line code:

Glide.with(view.getContext()).load(url).placeholder(R.drawable.default_profile).into(view);
相关标签:
11条回答
  • 2021-02-02 06:25

    Below is a weird fix that worked for me.

    The following always fails for me (12 trials) - I never see the real image:

    Glide.with(context)
     .load(url)
     .asBitmap()
     .into(new SimpleTarget<Bitmap>(iconWidth, iconHeight) { ... }
    

    The following always succeeds for me (12 trials) - I always see the real image:

    Glide.with(context)
     .load(url)
     .asBitmap()
     .listener(new RequestListener() {
        public boolean onException(Exception e,Object o,Target t,boolean b)
                   {return false;}
        public boolean onResourceReady(Object o,Object p,Target t,boolean b,boolean c)  
                   {return false;}})
     .into(new SimpleTarget<Bitmap>(iconWidth, iconHeight) { ... }
    

    As you can see, the only difference here is that I added a listener. Makes little sense, but these trials were done pretty carefully, so I'm going with it.

    0 讨论(0)
  • 2021-02-02 06:29

    Dont use transition or animation for Glide.It will solve your problem

    Code :

    Glide.with(context)
        .load(horizontalHappyHourList.get(position).getImage())
    //  .transition(DrawableTransitionOptions.withCrossFade(400)) //Optional
        .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.RESOURCE)
        .error(R.drawable.no_image))
        .into(holder.imageView);
    
    0 讨论(0)
  • 2021-02-02 06:30

    Add android:usesCleartextTraffic="true" in the application tag in manifest and check the internet permission is mentioned or not in the same manifest file:-

    0 讨论(0)
  • 2021-02-02 06:31

    If someone comes across this in the future you may need to add

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    

    Unsure of the exact reason for this change, nonetheless my code didn't work without that permission, and now does with it.

    0 讨论(0)
  • 2021-02-02 06:37

    Check if you have added Internet permission in the manifest:

    <uses-permission android:name="android.permission.INTERNET"/>
    

    Glide does not fire exception if there is no Internet connectivity.

    0 讨论(0)
提交回复
热议问题