如何使动画听者MonoDroid?听者、动画、MonoDroid

2023-09-03 04:30:28 作者:穿過你的黑發

我想利用这个机器人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));

从以上可以看出,为了实现我们也从的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).