Android Animation

Android Animation

Animation takes some parameters such as start value , end value, size , time duration , rotation angle e.t.c and perform the required animation on that object. It can be applied to any type of object. So in order to use this , android has provided us a class called Animation.

In order to perform animation in android , we are going to call a static function loadAnimation() of the class AnimationUtils. We are going to receive the result in an instance of Animation Object. Its syntax is as follows:

Note the second parameter. It is the name of the our animation xml file. You have to create a new folder called anim under res directory and make an xml file under anim folder.

This animation class has many useful functions which are listed below:

MethodDescription
start()This method starts the animation.
setDuration(long duration)This method sets the duration of an animation.
getDuration()This method gets the duration which is set by above method.
end()This method ends the animation.
cancel()This method cancels the animation.

In order to apply this animation to an object , we will just call the startAnimation() method of the object. Its syntax is:

Example

In this example i will show how to use make different Animation and to use that Animations.

VIDEO DEMO

Let’s get start by creating a project in Eclipse IDE.

1. Create a new project in Eclipse by navigating to File ⇒ New Android ⇒ Application Project and fill required details. (I kept my main activity name as MainActivity.java)

2.  Create a layout file for MainActivtiy.java under res ⇒ layout folder. I named the layout file as activity_main.xml. In this layout i had taken many Buttons to perform different Animations.

3. Now, create a new folder under res directory naming anim for creating animation xml files as told above. Here you are going to create all the animation files that you are going to need in code. I had made several different animation xml files.

4. Now, add the following code to MainActivity.java , in this activity i am going to show how to load the different animations and set them to views and use them.

5. Finally, run the app and you will get the output as shown in video.

Thanks. :)

Download Source Code – >

Leave a Comment

Comment (required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Name (required)
Email (required)