本文介绍了android:GIF动画循环完成监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张 GIF 图像,想在启动画面中加载.我遇到了几个像 android-gif-drawable 这样的库Glide

I have one GIF image and want to load in Splash Screen.I came across few libraries like android-gif-drawable and Glide

有什么办法可以让我听完一个动画周期吗?我的意思是一旦动画周期完成(整个动画完成,不重复)我想要一个监听器,动画完成,并为我们提供一些回调.有点像:

Is there any way I can listen for one animation cycle complete ?I mean once animation cycle is complete(whole animation is completed, without repeating) I want a listener, that Animation is complete, and provides us with some callback. Somewhat like:

SomeLibrary.load("GIF")
.into(imageview)
.repeat(false)
.setOnAnimationCompleteListener(new OnAnimationCompleteListener(){
    public void onAnimationComplete(){
        // Animation is completed. Do whatever you want to do..
    }
});

我使用过这两个库,但正在寻找我上面提到的功能.

I have worked with both libraries But looking for a feature as I mentioned above.

推荐答案

对于 Glide V4,我发现这是最好的答案.https://github.com/bumptech/glide/pull/3438

For Glide V4 I've found this to be the best answer. https://github.com/bumptech/glide/pull/3438

Glide.with(this).asGif().load(/*your gif url*/).listener(new RequestListener<GifDrawable>() {
    @Override
    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
        return false;
    }

    @Override
    public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
        resource.setLoopCount(1);
        resource.registerAnimationCallback(new Animatable2Compat.AnimationCallback() {
            @Override
            public void onAnimationEnd(Drawable drawable) {
                //do whatever after specified number of loops complete
            }
        });
        return false;
    }
}).into(imageView);

这篇关于android:GIF动画循环完成监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 10:31