August 4,2016
Animation is the process of creating motion and shape change
Animation in android is possible from many ways. In this chapter we will discuss one easy and widely used way of making animation called tweened animation.
Tween Animation
Tween 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 −
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.myanimation);
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 −
| Sr.No | Method & Description |
|---|---|
| 1 | start()
This method starts the animation. |
| 2 | setDuration(long duration)
This method sets the duration of an animation. |
| 3 | getDuration()
This method gets the duration which is set by above method |
| 4 | end()
This method ends the animation. |
| 5 | 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 −
ImageView image1 = (ImageView)findViewById(R.id.imageView1); image.startAnimation(animation);