Pro tip: Use Android's ObjectAnimator class to flip a view

Follow the three steps in this Android animation tutorial to learn how to achieve a wrap around the y-axis.

Animators are a hot topic in the Android world and in my TechRepublic articles. As consumer-facing apps compete for eyeballs in the market SDK and platform vendors are throwing more eye candy at developers than one can easily keep up with. Slick transitions that used to require third-party libraries like NineOldAndroids and complicated custom animations using Android's 3D Camera class can now be pulled off with little effort.

I have spoken to a number of developers who agree with me that lately it's difficult just keeping up with what options are at our disposal. This tutorial shows how easily Android's ObjectAnimator class can achieve what was previously difficult animation: a wrap around the y-axis. If you prefer, you can download and import the entire project directly into Eclipse.

1. Create a new Android project. You need to target Android 3.1 (Honeycomb) or better.

2. In the /res folder, modify the activity_main.xml layout to center a single text view on the screen.

<RelativeLayout xmlns:android=""
    android:background="#000000" >

        android:text="@string/hello_world" />


3. In the /src folder, open the file. Load the animation in the on create override and apply it to the view.
package com.authorwjf.rotateonyaxis;

import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.animation.ObjectAnimator;

public class MainActivity extends Activity {

	protected void onCreate(Bundle savedInstanceState) {
		View v = findViewById(;
		ObjectAnimator animation = ObjectAnimator.ofFloat(v, "rotationY", 0.0f, 360f);
		animation.setInterpolator(new AccelerateDecelerateInterpolator());


Believe it or not, we're done. Check out the demo video for yourself.

The key to knowing what you can do with the ObjectAnimator class is knowing what properties can be animated. It takes a bit of digging to find on the Android Developers site, but here is the list of properties you can play with.

If you enjoy working with Android animations, why not enter our code challenge? The deadline has been extended to Friday, December 6th.

By William J. Francis

William J Francis began programming computers at age eleven. Specializing in embedded and mobile platforms, he has more than 20 years of professional software engineering under his belt, including a four year stint in the US Army's Military Intellige...