Android comes with built-in support for animations in the core of the platform. There is a class called Animation.AnimationListener wich provides tons of helpers to animate many aspects of an Androi app.
Let's take a look at it. We are going to use animations configurated both in XML and programmatically. For the first animation we'll fall down a TextView using XLM. After that we will fade in and out the text.
In the resources we can defina a new folder called anim. All of our animations XML will be in this place. For the first one the idea is simple: Move the TextView from a Y position to another Y position on 4 seconds. Take a look at the file below to see this configuration.
Now that we have the idea of the animation, we nee to link it to our TextView. To do that, we need to add some code to the Activity. In the code below, we define the animation XML we'll use, set an animation listener (will be useful, for example, to do some code after animation stops) and start the animation.
Next step is to configure this Activity as an Activity which knows about animations. This is possible implementing the Animation.AnimationListener and overriding 3 methods like in the code below.
Now we have configured a simple animation using XML, let's add a second one programmatically. The idea now is to fade in/out the TextView, right after fall down animation ends.
To do that, we can start a nem animation in the onAnimationEnd method we previously created. We will define AlphaAnimation, offset and duration.
To infinity and Beyond
After understanding the basics, you can go a little deeper in animations for Android. Below we have 2 interesting links about this subject.
Displaying Card Flip Animations
Pluralsight - Android Animations Course
comments powered by Disqus