Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use animation in xamarin android application?

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

like image 349
Ali pishkari Avatar asked Jun 15 '15 09:06

Ali pishkari


People also ask

Which animation system is used in Android application?

The animations are basically of three types as follows: Property Animation. View Animation. Drawable Animation.

Can we do animation in Android?

On Android 4.4 (API level 19) and higher, you can use the transition framework to create animations when you swap the layout within the current activity or fragment. All you need to do is specify the starting and ending layout, and what type of animation you want to use.

What is Property animation in Android?

A property animation changes a property's (a field in an object) value over a specified length of time. To animate something, you specify the object property that you want to animate, such as an object's position on the screen, how long you want to animate it for, and what values you want to animate between.


2 Answers

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);
        }
like image 135
Ali pishkari Avatar answered Oct 03 '22 09:10

Ali pishkari


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 ...

like image 32
jackw11111 Avatar answered Oct 03 '22 08:10

jackw11111