Reputation: 157
I'm trying to find how can I set a GIF image in image button and set it to play only once.
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);
Upvotes: 3
Views: 7260
Reputation: 447
Java version to the Billy's answer to load gif into image view and control how many loops you want:
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));
Upvotes: 8
Reputation: 2168
Please try to add a RequestListener
. And set the loop count in OnResourceReady()
.
For example:
Glide.With(this).AsGif().Load(Resource.Mipmap.giphy).Listener(new MyRequestListener()).Into(ib_main_home);
And the 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;
}
}
Please check the following link for more information: https://github.com/bumptech/glide/issues/1706#issuecomment-282827419
Upvotes: 8