Add Simple animations in your android application

Updated 22 September 2017

Save

In this blog, we will learn about how you can add simple animations in your android application.

We all know that adding some small animations in your application can indeed increase the User Experience and the User Engagement of your application.

While you can definitely use some animation libraries like Lottie (from Airbnb) and Shimmer (from facebook). But do we really need their animation? The answer, in reality, is “NO”.
The Android supports many simple animations by default and you can use them on your views and their use is very easy.

If you are new to android animations you can read this blog and get a quick start :

Some basic animations in Android

 

After reading this small piece, you can easily understand that adding animations is a very easy task.

Also, You can start trying the basic animation by just using this line whenever you start a new activity

See, using animations is as easy as adding this simple line.

Now, we will learn how to add some animations to some views so that when they are created they appear with some animation.

APPROACH :

  1. In the”res” folder of your project, create a new folder and name it “anim”.
  2. You need to create an xml file in which you will write the code for your animation.
  3.  Get the object of the view in your activity/fragment.
  4. Call the startAnimation() method on the view. This method call requires you to send an object of animation in params.
  5. You can either create a new animation object and assign it the value returned by AnimationUtils.loadAnimation()method or directly pass the AnimationUtils.loadAnimation() method in the method used in step4.
  6.  The AnimationUtils.loadAnimation() method takes two paramaters : first one is the Context , second one is the id of your xml file in which the animation is set. You need to pass the resourceId of the file you created in step2 (something like R.anim.your_file_name)

 

CODE :

my_custom_animation_horizontal_scrolling.xml

my_custom_animation_vertical_bounce.xml

 

Code in your Activity :

And it is done.

For seeing the demo of what these animations will be like check the gif.
The “Simple animations demo ” view has bounce effect on it and the “By : Anchit Makkar” has horizontal movement effect on it.

 

You can explore more animations by changing the values in XML. Explore more till you find what you need

 

 

 

 

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home