开发者

How to use SetAnimationListener()?

I would like to know when my animation is finished, so I have to use an AnimationListener.

I cannot seem to find out how to do that in MonoDroid (C#).

Does anyone know how to do开发者_如何学运维 this ?


Here is a short one I wrote to get me a callback when the animation ends:

class AnimationListenerEndCallback : Java.Lang.Object, Animation.IAnimationListener
{
    public delegate void Callback(Animation animation);
    private Callback callback;
    public AnimationListenerEndCallback(Callback callback)
    {
        this.callback = callback;
    }

    public void OnAnimationEnd(Android.Views.Animations.Animation animation)
    {
        callback(animation);
    }

    public void OnAnimationRepeat(Android.Views.Animations.Animation animation)
    {
        // do nothing
    }

    public void OnAnimationStart(Android.Views.Animations.Animation animation)
    {
        // do nothing
    }
}

You use it like this:

Animation a = AnimationUtils.LoadAnimation(this, Resource.Animation.pull_up);
a.SetAnimationListener(new AnimationListenerEndCallback(delegate
{
   // all your local variables are still in scope, so you
   // can use them here
}));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜