Android Animation

Android Animation is used to give the UI a rich look and feel. Animations in android apps can be performed through XML or android code. In this android animation tutorial we'll go with XML codes for adding animations into our application.

We will create animation one by one, so let's start


Fade Animation

Create res/anim/fade_in.xml

<set xmlns:android="https://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

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

</set>

Create res/anim/fade_out.xml

<set xmlns:android="https://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

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

</set>

How to load Animation

We need to use the Animation Class. The xml file that contains the animation logic is loaded using AnimationUtils class by calling the loadAnimation() function.

In Below code snippet View is that object where you want to show animation, Now the below snippet shows this implementation:

Animation animation = AnimationUtils.loadAnimation(this, R.anim.slide_down);

view.setAnimation(animation);
view.startAnimation(animation);


Download: All Animation Source Code Download Here