【问题标题】:Play GIF image in glide once在滑行中播放 GIF 图像一次
【发布时间】:2021-07-27 04:08:03
【问题描述】:

我正在尝试查找如何在图像按钮中设置 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);

【问题讨论】:

    标签: c# android xamarin android-glide


    【解决方案1】:

    请尝试添加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

    【讨论】:

    • 你能分享一下java等价物吗?
    • 它应该几乎相同,因为 Xamarin 被构建为 Android SDK 上的瘦包装器
    • @Arjun 这篇文章应该对你有所帮助 - stackoverflow.com/questions/35645199/…
    【解决方案2】:

    Billy 的 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));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-16
      • 1970-01-01
      • 1970-01-01
      • 2012-03-18
      • 2017-05-06
      • 2023-03-28
      • 1970-01-01
      • 2012-07-10
      相关资源
      最近更新 更多