Glide: loading gif image not working in placeholder

Created on 30 Sep 2015  路  5Comments  路  Source: bumptech/glide

i use glide for my app but the loading gif image is not working..
please help me im new to android.. i use android studio..

this is my code..

imageView = (ImageView) rootView.findViewById(R.id.imageView);
String url = "http://joehamirbalabadan.com/android/android/imghome/index1.png";
Glide.with(getActivity()).load(url).placeholder(R.drawable.indexloading).into(imageView);

Thanks,
Joe

question

Most helpful comment

One thing to try, Joe, is:
(static placeholder is, say, the first frame of the GIF)

Glide...
.load("http://...")
.placeholder(R.drawable.static_placeholder)
.thumbnail(Glide.with(...).load(R.raw.gif_placeholder))
.dontAnimate() //so there's no weird crossfade

placeholder is set much earlier than thumbnail, so it prevents "long" empty white ImageViews. You can skip the placeholder to simplify though.

or what Sam said in code (with all anim in xml):

AnimationDrawable animPlaceholder = (AnimationDrawable)context.getDrawable(R.drawable.animatedDrawable);
animPlaceholder.start(); // probably needed
Glide...
.load("http://...")
.placeholder(animPlaceholder)

All 5 comments

I don't think you can have a GIF as a drawable. Placeholders are loaded by the framework, which doesn't support this. You can maybe work around it by using an animated Drawable, but I'm not sure. GIF support in Glide is currently for load() because it takes additional steps to decode each frame and update the drawable set into the ImageView.
@sjudd is this correct? What happens if the GIF is in raw?

@TWiStErRob You're correct, Android doesn't include support for animated GIFs. At best you're going to get a still frame from the GIF. If the GIF is in raw, you can decode it with Glide (load(R.raw.my_gif_id)), but that's about it.

If you have a type of animated Drawable Android does support, you should be able to pass it into placeholder. You may need to call start() on it manually though, which would require passing a Drawable, rather than a resource id, to Glide.

One thing to try, Joe, is:
(static placeholder is, say, the first frame of the GIF)

Glide...
.load("http://...")
.placeholder(R.drawable.static_placeholder)
.thumbnail(Glide.with(...).load(R.raw.gif_placeholder))
.dontAnimate() //so there's no weird crossfade

placeholder is set much earlier than thumbnail, so it prevents "long" empty white ImageViews. You can skip the placeholder to simplify though.

or what Sam said in code (with all anim in xml):

AnimationDrawable animPlaceholder = (AnimationDrawable)context.getDrawable(R.drawable.animatedDrawable);
animPlaceholder.start(); // probably needed
Glide...
.load("http://...")
.placeholder(animPlaceholder)

hi twisterrob,

can you give a sample code that work in a fragment?
sorry im just new to android..

i tried to do this code..

Drawable animPlaceholder = context.getDrawable(R.drawable.animatedDrawable);
animPlaceholder.start(); // probably needed
Glide...
.load("http://...")
.placeholder(animPlaceholder)

but the start() is error, it say Cannot resolve..

Thanks,
Joe

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PatrickMA picture PatrickMA  路  3Comments

MrFuFuFu picture MrFuFuFu  路  3Comments

Anton111111 picture Anton111111  路  3Comments

billy2271 picture billy2271  路  3Comments

Morteza-Rastgoo picture Morteza-Rastgoo  路  3Comments