我如何使用xamarin Android应用动画? [英] How can I use animation in xamarin android application?

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

问题描述

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

I want to use animation in my android Application using Xamarin C#. animations like fade-in, zoom-in, move and ....

推荐答案

首先添加下的文件夹资源文件夹命名为动画。
,那么你可以添加动画资源给它,
例如:用于淡​​入动画创建动画的文件夹并命名为fade_in.xml下一个资源,这个代码粘贴到它:

first add a folder under "resources " folder name it "anim". then you can add your animation resources to it , Ex: for fade-in animation create a resource under anim folder and name it "fade_in.xml" and paste this code into it:

<?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,也是一个按钮

then add a Textview in your mainlayout.xml and also a button

 <TextView
            android:text="Text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/txtMessage"
            android:layout_marginBottom="35.3dp" />



和按钮:

and for button:

<Button
                android:text="fade in"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/fadein" />

在的OnCreate方法,你的活动添加以下代码:

in "oncreate" method in you activity add this code :

  Button fadein = FindViewById<Button>(Resource.Id.fadein);
            fadein.Click += btn_Click;



则此方法添加到您的活动:

then add this method to your activity:

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);
        }

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

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