As the number of apps in Google Play continues to grow, it’s no longer always enough to write a quality application that does a job well. Given two apps that perform equally well, users tend to gravitate to the one with the more interesting user experience. In fact, I know some users who will choose a less functional app when presented with enough eye candy.

Luckily, you don’t have to be a UI jedi to whip up some pretty slick animations. The folks at Google are constantly adding functions to the API to make the job of creating smooth fades and eye-catching transitions a breeze. In this tutorial we will explore the ObjectAnimator, a straightforward class for manipulating object properties resulting in impressive animations that can be applied to any view or widget. You can follow along with the step-by-step instructions below, or download and import the entire project into Eclipse.

1. Start a new Android project in Eclipse. You must target at a minimum SDK version 11 (Honeycomb).  Name your startup activity and the layout main.xml, respectively.

2. In our /res/layout folder, we will modify main.xml to consist of a linear layout and two widgets: a text view and a button.


<LinearLayout xmlns:android=""
        android:text="Apply Transition"
        android:id="@+id/button" />

3. We will move on to the /src/ file. The on create override is your standard Android UI paradigm: attach a layout and wire up the button. Meanwhile, our on click handler is where the magic happens. You can see how handily the object animator combines with the animator set and builder to allow us to apply multiple transitions to a single object in tandem.

package com.authorwjf.transition;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
public class Main extends Activity implements OnClickListener{

private final boolean IN = true;
       private boolean state = IN;
   public void onCreate(Bundle savedInstanceState) {
       public void onClick(View v) {
              TextView tv = (TextView)findViewById(;
              tv.setText("Hello Transition!");
              ObjectAnimator scaleXOut = ObjectAnimator.ofFloat(tv, "scaleX", 1f, 0f);
          ObjectAnimator scaleXIn = ObjectAnimator.ofFloat(tv, "scaleX", 0f, 1f);
          ObjectAnimator scaleYOut = ObjectAnimator.ofFloat(tv, "scaleY", 1f, 0f);
          ObjectAnimator scaleYIn = ObjectAnimator.ofFloat(tv, "scaleY", 0f, 1f);
          ObjectAnimator rotateClockWise = ObjectAnimator.ofFloat(tv, "rotation", 0f, 360f);
          ObjectAnimator rotateCounterClockWise = ObjectAnimator.ofFloat(tv, "rotation", 0f, -360f);
          AnimatorSet set = new AnimatorSet();
          if (state == IN) {
             } else {
             state = !state;

Are you ready for some GUI goodness? Load up the demo and give it a whirl (Figure A). Pressing the button causes the text to alternately transition in and out, spinning while simultaneously shrinking or growing. You have to admit, the resulting animation is pretty cool, and the API does all the hard work.
Figure A

If you were not already dressing up your apps with Google’s animation framework, I encourage you to investigate it further. You can read Google’s complete and official documentation for Property Animation.