如何使动画听者MonoDroid? [英] How to make an animation listener in MonoDroid?

查看:123
本文介绍了如何使动画听者MonoDroid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想利用这个机器人code并将其转换为monoDroid

I want to take this android code and convert it to monoDroid

Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.fade_in2);
fade2.setAnimationListener(new AnimationListener() {
    public void onAnimationEnd(Animation animation) {
        startActivity(new Intent(QuizSplashActivity.this,
            QuizMenuActivity.class));
        QuizSplashActivity.this.finish();
    }
});

我有这到目前为止

I have this so far

Animation fade2 = AnimationUtils.LoadAnimation(this, Resource.Animation.Fade_in2);
 fade2.SetAnimationListener(????);

我没有看到新的AnimationListener()。看来OT希望某些接口或什么的。

I don't see new AnimationListener(). It seems ot want some interface or something.

推荐答案

您的Java源代码code是利用匿名内部类的:

Your source Java code is making use of anonymous inner classes:

fade2.setAnimationListener(new AnimationListener() {...});

C#不支持这些(C#3匿名类型不以任何方式类似于Java的匿名内部类),所以你需要提供一个明确的类型并使用它:

C# doesn't support these (C# 3 anonymous types are in no way similar to Java anonymous inner classes), so you need to provide an explicit type and use that instead:

class MyAnimationListener : Java.Lang.Object,
        Android.Views.Animations.Animation.IAnimationListener
{
    Activity self;

    public MyAnimation (Activity self)
    {
        this.self = self;
    }

    public void OnAnimationEnd (Animation animation)
    {
        self.StartActivity (new Intent (self, typeof (QuizMenuActivity)));
        self.Finish ();
    }

    public void OnAnimationRepeat (Animation animation)
    {
    }

    public void OnAnimationStart (Animation animation)
    {
    }
}

// ...
fade2.SetAnimationListener (new MyAnimationListener (this));

从以上可以看出,为了实现我们也从<一个继承接口href="http://android.xamarin.com/Documentation/Architecture/Android_Callable_Wrappers#Implementing_Interfaces"相对=nofollow>的java.lang.Object (这个工具 Android.Runtime.IJavaObject 我们)和,而不是含蓄引用 QuizSplashActivity.this 因为是用Java做的,而是我们需要明确捕获它作为一个字段。

As seen above, to implement the interface we also inherit from Java.Lang.Object (this implements Android.Runtime.IJavaObject for us), and instead of implicitly referencing QuizSplashActivity.this as is done in Java, we instead need to explicitly capture it as a self field.

这可以通过提供一个辅助基本类型被简化(我想,在C的Java $ C $的 AnimationListener 所有的动画是一个辅助类,不被提供.AnimationListener方法,这样做在C#中〜同样的事情也行)。

This could be simplified by providing a helper base type (I imagine that in the Java code the AnimationListener is a helper type, as not all of the Animation.AnimationListener methods were provided, so doing the ~same thing in C# would work as well).

这篇关于如何使动画听者MonoDroid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆