Malik A. Abualzait
Malik A. Abualzait

Reputation: 33

I am using Glide to load a gif image from url, however it keeps looping

I am using Glide to load a gif file from url, however it keeps looping. is there anyway to set a counter for looping for example just to play the animation 1 time.

Upvotes: 1

Views: 2965

Answers (2)

Al-Amin
Al-Amin

Reputation: 1387

You may try like this -

Glide.with(getContext())
        .load(R.drawable.some_gif)
        .into(new GifDrawableImageViewTarget(mGifView, 1));

Upvotes: 0

Krishna Sharma
Krishna Sharma

Reputation: 2877

Add RequestListener, here is the sample code

Glide.with(<context>)
                .load(uri.toString())
                .listener(new RequestListener<Drawable>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                        if (resource instanceof GifDrawable) {
                            ((GifDrawable) resource).setLoopCount(1);
                        }
                        return false;
                    }
                })
                .into(<your imageview>);

Upvotes: 2

Related Questions