在Glide中播放GIF图片一次

3
我正在尝试找到如何在图像按钮中设置GIF图像并仅播放一次的方法。
SetContentView(Resource.Layout.activity_main);
        var ib_main_home = FindViewById<ImageButton>(Resource.Id.ds);
        Glide.With(this).AsGif()
 .Load(Resource.Mipmap.giphy)
 .Into(ib_main_home);
2个回答

8

请尝试添加一个RequestListener,并在OnResourceReady()中设置循环次数。 例如:

Glide.With(this).AsGif().Load(Resource.Mipmap.giphy).Listener(new MyRequestListener()).Into(ib_main_home);

还有RequestListener

public class MyRequestListener :Java.Lang.Object, IRequestListener
{
    public bool OnLoadFailed(GlideException p0, Java.Lang.Object p1, ITarget p2, bool p3)
    {
        return true;
    }

    public bool OnResourceReady(Java.Lang.Object p0, Java.Lang.Object p1, ITarget p2, DataSource p3, bool p4)
    {
        if (p0 is GifDrawable)
        {
            ((GifDrawable)p0).SetLoopCount(1);
        }
        return false;
    }
}

请查看以下链接以获取更多信息: https://github.com/bumptech/glide/issues/1706#issuecomment-282827419

1
请问您能分享一下Java的等效代码吗? - Arjun
Xamarin被设计为Android SDK的薄包装器,因此它几乎相同。 - Eman
@Arjun 这篇文章应该会对你有所帮助 - https://dev59.com/kFsV5IYBdhLWcg3w6iV8 - Oush

8

这是关于Java版本的内容,用于加载gif并控制你想要的循环次数。

Glide.with(this)
            .asGif()
            .load(R.raw.onboarding_layers) //Your gif resource
            .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE))
            .listener(new RequestListener<GifDrawable>() {
                @Override
                public boolean onLoadFailed(@Nullable @org.jetbrains.annotations.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);
                    return false;
                }
            })
            .into((ImageView) view.findViewById(R.id.layer_icons));

RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE) 是用来做什么的? - Marfin. F

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接