Ways to Animate things in Android.

Vandana Srivastava
2 min readJun 11, 2021

--

This article is to share some experience which I had while working on my project. I have to do some work on animations but I didn’t have much clue from where to start. So I wanted to share this, maybe in the future both will benefit.

Below is the demo of the animation sample which I have created to achieve the animation style asked by my designer. Due to privacy reason, I can’t share exact animation in demo which is being used in the live app.

Let’s start the real discussion now.

In my project I had to make a flying heart with flash animation in it.

Firstly, I thought to go with Lottie library and for single animation it is working fine. But if I had to show multiple animations at same time it seems a little tricky, as you have to create `N` numbers of objects of LottieAnimationView which may cause OutOfMemory error if not handled properly.

Where, N is the number of clicks on the button.

Below is the code sample which create multiple LottieAnimationView in given FrameLayout and remove it when animation ends and how to call this on button click.

Below is the code to show multiple Lottie animation view on button click.

Then, I thought to explore more, the second approach was to create a path on which the heart drawable will fly. But in this, I done a lot of mathematical calculations according to x and y coordinates and density pixels, which took a lot of time to implement.

Because doing lot of calculation and then drawing path source code to bit lengthy and won’t be good to attaching gist here. At the end, Github repository link is there for looking into full source code.

Third and last which came into my mind, to create animation using ObjectAnimator and animate that drawable on layout which is defined in xml.

Below is code sample to do animation using ObjectAnimator.

Below is the code of button click to call above function

So, these were some approaches which I went through. Maybe this seems helpful for those who are working on animations.

Below is Github repository link for full source code of demo app. If you like my work, don’t forget to star and add your contribution by forking it.

If you have good resources such as website or blog links or ebooks/books on animations please add in comment. Let’s learn together.

Thanks.

--

--

No responses yet