How can I use animation in xamarin android application?

9.1k views Asked by At

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

2

There are 2 answers

0
Ali pishkari On BEST ANSWER

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>

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" />

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);
        }
0
jackw11111 On

You can make a simple fade animation like this :

txtMessage.Alpha = 0.0f;
txtMessage.Animate().Alpha(1.0f).SetDuration(1000).Start();

You can also animate other properties such as ScaleX, RotationX, TranslationX, etc ...