Glide: How can i load the GIF without animation

Created on 20 Jan 2016  路  3Comments  路  Source: bumptech/glide

how can i stop the animation? If the file type must be GIF.

question

Most helpful comment

If you want to start/stop on user request: load as normal (or force with asGif()) and in a click listener:

Drawable drawable = imageView.getDrawable();
if (drawable instanceof Animatable) {
    Animatable gif = (Animatable)drawable;
    if (gif.isRunning()) gif.stop() else gif.start();
}

All 3 comments

.load().asBitmap() will load the first frame. This is the most effective.

Otherwise check how GlideDrawableImageViewTarget starts the drawable: you can extend that class and stop it immediately after super starts it and use into(new MyStoppedGDIVT(imageView)) instead of into(imageView). You'll also need to explicitly apply a transformation (centre crop or fit center). Note that this version still loads all the GIF bytes into memory, even though only the first frame will be displayed. You may be able to display any frame by programmatically advancing the drawable.

@TWiStErRob I'll try it. Thanks!!!

If you want to start/stop on user request: load as normal (or force with asGif()) and in a click listener:

Drawable drawable = imageView.getDrawable();
if (drawable instanceof Animatable) {
    Animatable gif = (Animatable)drawable;
    if (gif.isRunning()) gif.stop() else gif.start();
}
Was this page helpful?
0 / 5 - 0 ratings