Glide not loading real image and stuck with placeholder

后端 未结 11 730
长情又很酷
长情又很酷 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:14

    Incase none of the above solves it, and you're setting the 'src' property on the ImageView, it won't work. I was mistakenly setting the 'src' on the ImageView in xml and taking that out solved it for me.

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

    Try to add .dontAnimate() It caused by TransitionDrawable too and it seems so because after scroll there's no animation because it's cached.

    The correct code is

    Glide.with(view.getContext()).load(url).placeholder(R.drawable.default_profile).dontAnimate().into(view);
    

    I hope it will be helpful for you.

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

    None of the solutions above worked for me. The issue may be at the placeholder you're using. If the view you're using to load the image has a placeholder, it causes some issues. Removing that placeholder for some reason seems to fix it.

    So, if the (Image)View you're trying to inflate has a placeholder, such as android:src="@mipmap/placeholder", remove it.

            <ImageView
                android:id="@+id/imgGallery"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
                android:src="@mipmap/rugova1" />
    

    like this

     <ImageView
                android:id="@+id/imgGallery"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
                />
    

    It worked for me.

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

    May help someone :) My issue was network security policy exception. The URL requested by Glide was blocked by android due to security policy.

    Fixed by whitelisting desired domain. Check here

    com.bumptech.glide.load.engine.GlideException: Failed to load resource
    There was 1 cause:
    java.net.UnknownServiceException(CLEARTEXT communication to maps.googleapis.com not permitted by the network security policy)
     call GlideException#logRootCauses(String) for more detail
    

    The toughest thing is it was not shown in the normal log.

    0 讨论(0)
  • Seems strange but only thing I could guess is Your URL is valid as You already said. Your remote is getting downloaded even getting applied on your image view but your placeholder is somehow hiding it. Glide has some bugs related to placeholder stuff.

    My suggestion would be to try below:

    Glide.with(view.getContext()).load(url).
    placeholder(R.drawable.default_profile).fitCenter().into(view);
    

    So the trick is placeholder is set via setImageDrawable() so the ImageView will just display it as usual, but you tell Glide to use the fitCenter explicitly which will fit the loaded image nicely within the ImageView's laid out size via a Transformation and then set it via setImageDrawable(). Since the fitted image is a perfect fit, center will just draw the image covering the whole area of the view.

    Give it a try.

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

    Use ProgressBar as loading gif

    Glide.with(context).
            load(url)
            .listener(new RequestListener<String, GlideDrawable>() {
                @Override
                public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                    progressBar.setVisibility(View.GONE);
                    return false;
                }
    
                @Override
                public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                    progressBar.setVisibility(View.GONE);
                    return false;
                }
            })
            .crossFade(1000)
            .into(imageView);
    
    0 讨论(0)
提交回复
热议问题