我有一张 GIF 图像,想要在启动屏幕中加载。
我遇到过几个像这样的图书馆android-gif-可绘制 https://github.com/koral--/android-gif-drawable and Glide https://github.com/bumptech/glide
有什么方法可以听完整的一个动画周期吗?
我的意思是一旦动画周期完成(整个动画完成,不重复),我想要一个监听器,动画完成,并为我们提供一些回调。有点像:
SomeLibrary.load("GIF")
.into(imageview)
.repeat(false)
.setOnAnimationCompleteListener(new OnAnimationCompleteListener(){
public void onAnimationComplete(){
// Animation is completed. Do whatever you want to do..
}
});
我已经使用过这两个库,但正在寻找我上面提到的功能。
对于 Glide V4,我发现这是最好的答案。https://github.com/bumptech/glide/pull/3438 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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)