首先在“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>
然后在 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" />
对于按钮:
<Button
android:text="fade in"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/fadein" />
在您活动的“oncreate”方法中添加以下代码:
Button fadein = FindViewById<Button>(Resource.Id.fadein);
fadein.Click += btn_Click;
然后将此方法添加到您的活动中:
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);
}