Glide images sometimes are not loading

后端 未结 3 893
小鲜肉
小鲜肉 2020-12-04 01:11

Is a quiz game and the answer can be text or image, i\'m using Gilde image to load it but for some users the images can\'t load, even if the internet is good and the images

相关标签:
3条回答
  • 2020-12-04 01:45

    I have followed everything.

    Added .dontAnimate Added all necessary permissions, Internet, Access_Network_State

    But nothing works.

    Finally I found the reason for image not loading, my Image url doesn't have http or https. I have added http:// in front of my image url and it loads perfectly.

    0 讨论(0)
  • 2020-12-04 01:51

    the best way to use glide I am explaining here.

    //crete this method into your Utils class and call this method wherever you want to use.
    //you can set these placeHolder() and error() image static as well. I made it as comment inside this method, then no need to use [placeHolderUrl and errorImageUrl] parameters. remove it from this method.
    public static void loadImage(final Activity context, ImageView imageView, String url, int placeHolderUrl, int errorImageUrl) {
        if (context == null || context.isDestroyed()) return;
    
        //placeHolderUrl=R.drawable.ic_user;
        //errorImageUrl=R.drawable.ic_error;
            Glide.with(context) //passing context 
                    .load(getFullUrl(url)) //passing your url to load image.
                    .placeholder(placeHolderUrl) //this would be your default image (like default profile or logo etc). it would be loaded at initial time and it will replace with your loaded image once glide successfully load image using url.
                    .error(errorImageUrl)//in case of any glide exception or not able to download then this image will be appear . if you won't mention this error() then nothing to worry placeHolder image would be remain as it is.
                    .diskCacheStrategy(DiskCacheStrategy.ALL) //using to load into cache then second time it will load fast.
                    .animate(R.anim.fade_in) // when image (url) will be loaded by glide then this face in animation help to replace url image in the place of placeHolder (default) image.
                    .fitCenter()//this method help to fit image into center of your ImageView 
                    .into(imageView); //pass imageView reference to appear the image.
    }
    

    fade_in.xml (put it into res->anim)

    <set xmlns:android="http://schemas.android.com/apk/res/android">
    <!--THIS ANIMATION IS USING FOR FADE IN -->
    
    <alpha
        android:duration="800"
        android:fromAlpha="0.0"
        android:interpolator="@android:anim/decelerate_interpolator"
        android:toAlpha="1.0" />
    

    and finally call this method

    from your Activity.

    Utils.loadImage(YourClassName.this,mImageView,url,R.drawable.ic_user,R.drawable.ic_error);
    

    OR

    from your fragment

    Utils.loadImage(getActivity,mImageView,url,R.drawable.ic_user,R.drawable.ic_error);
    
    0 讨论(0)
  • 2020-12-04 02:05

    In my case in Glide 4.8.0 the adding the following to ImageView widget into which Glide was loading did the trick, wierd but it works....

    android:background="?attr/selectableItemBackgroundBorderless"
    

    Or Also

    android:background="@drawable/R.drawable.yourResourceFile
    

    Or Also

    android:background="@android:color/transparent"
    
    0 讨论(0)
提交回复
热议问题