如何在xamarin android应用程序中使用动画?

Ali*_*ari 6 c# android xamarin titanium-android

我想在我的Android应用程序中使用Xamarin C#动画.动画,如淡入,放大,移动和....

Ali*_*ari 13

首先在"resources"文件夹下添加一个文件夹,命名为"anim".然后你可以添加你的动画资源,例如:对于淡入动画,在anim文件夹下创建一个资源,并将其命名为"fade_in.xml"并将此代码粘贴到其中:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

    <alpha
        android:duration="1000"
        android:fromAlpha="0.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toAlpha="1.0" />

</set>
Run Code Online (Sandbox Code Playgroud)

然后在mainlayout.xml中添加Textview以及一个按钮

 <TextView
            android:text="Text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/txtMessage"
            android:layout_marginBottom="35.3dp" />
Run Code Online (Sandbox Code Playgroud)

和按钮:

<Button
                android:text="fade in"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/fadein" />
Run Code Online (Sandbox Code Playgroud)

在您的活动中的"oncreate"方法中添加以下代码:

  Button fadein = FindViewById<Button>(Resource.Id.fadein);
            fadein.Click += btn_Click;
Run Code Online (Sandbox Code Playgroud)

然后将此方法添加到您的活动中:

void blink_Click(object sender, EventArgs e)
        {
            txtMessage = FindViewById<TextView>(Resource.Id.txtMessage);
             Button b = sender as Button;
            Animation anim = AnimationUtils.LoadAnimation(ApplicationContext,
                           Resource.Animation.fade_in);
             txtMessage.StartAnimation(anim);
        }
Run Code Online (Sandbox Code Playgroud)