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
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
You need a cast to AnimationDrawable: http://developer.android.com/guide/topics/graphics/drawable-animation.html
Most helpful comment
One thing to try, Joe, is:
(static placeholder is, say, the first frame of the GIF)
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):