Anima on in Android:-
1. Android Animation is used to give the UI a rich look and feel.
2. Anima on in Android refers to the visual effects applied to UI elements to enhance
the user experience by providing smooth transi ons, movements, and
transforma ons.
3. It can be used for various purposes, such as to draw a en on to specific elements,
make the interface more dynamic, and improve the overall usability of the
applica on.
4. Animations in android apps can be performed through XML code.
5. Animation in android apps is the process of creating motion and shape change.
6. [Link] package is used for animation.
The animations are basically of three types as follows:
1. Property Animation:
These provide more flexibility and are used to animate proper es of objects over
me. Property anima ons allow complex transforma ons such as changing a view’s
posi on, rota on, opacity, and more, while offering be er control over the dura on
and ming.
2. View Animation:
These are used to animate UI elements like bu ons, text, images, and other view
components. The most common view anima ons are:
o Tween Anima on: Includes transforma ons like transla on, rota on, scaling,
and fading (e.g., TranslateAnima on, RotateAnima on, ScaleAnima on,
AlphaAnima on).
o Frame-by-frame Anima on: Used to create sprite-based anima ons by
displaying a sequence of images at a set frame rate.
3. Drawable Animation:
Drawable Animation is used if you want to animate one image over another. A simple
example of drawable animation can be seen in many apps Splash screen on apps logo
animation.
The basic ways of animation are:
1. Fade In Animation
2. Fade Out Animation
In android, Fade In and Fade Out animations are used to change
the appearance and behavior of the objects over a particular
interval of time. The Fade In and Fade Out animations will provide
a better look and feel for our applications.
3. Blink Animation
This feature can be used to show important announcements or
notifications in an App. Even we can add this feature to show
important links for the user.
4. Zoom In Animation
5. Zoom Out Animation
Zooming is an in-motion operation done to enlarge or reduce
the size of an image or an object in an Android application.
6. Rotate Animation
An animation that controls the rotation of an object. This rotation
takes place in the X-Y plane. You can specify the point to use for
the center of the rotation, where (0,0) is the top left point. If not
specified, (0,0) is the default rotation point.
7. Move Animation
Objects on screen will often need to be repositioned. This can
occur due to user interaction or some processing done behind the
scenes. Instead of immediately updating the objects position, which
would cause it to blink from one area to another, you should use an
animation to move it from the starting position to its end position.
8. Slide Up Animation
9. Slide Down Animation
slide up and slide down animations slide an image/views up or
down.
Animation and AnimationUtils class
In order to perform animation in android , we are going to call a static function
loadAnimation() of the class AnimationUtils.
Steps to apply animation to an image:-
[Link] are going to receive the result in an instance of Animation Object. Its syntax is as
follows −
Animation animation = [Link](getApplicationContext(),
[Link]);
[Link] the second parameter. It is the name of the our animation xml file.
Steps to create anim directory-
We create a resource directory under the res folder names anim to keep all the xml files
containing the animation logic.
Steps : Right click on res Directory –New-Android Resource Directory – select resource type
as anim and give name anim to your directory.
Right click on anim directory- New- Animation Resource file- give name to your file as
[Link] (Do these steps to create all other animation xml files)
3. 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([Link].imageView1);
[Link](animation);