簡體   English   中英

在滑行中播放 GIF 圖像一次

[英]Play GIF image in glide once

我試圖找到如何在圖像按鈕中設置 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);

請嘗試添加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

將 gif 加載到圖像視圖中並控制所需循環次數的比利答案的 Java 版本:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM