Android Animation Advanced

We have one more advanced animation API from API12.
View class has animation API directly.
We don’t have to make Animation class anymore, and use them directly

ViewPropertyAnimator

View has animate() method. This returns ViewPropertyAnimator
This is kay class. This keeps all animation parameter, and all methods return ViewPropertyAnimator itself. It means this class is Builder style.

Sample

Simple Example

View blockView = getLayoutInflater().inflate(R.layout.block, null);
LayoutParams params = new RelativeLayout.LayoutParams( LayoutParams.MATCH_PARENT , LayoutParams.MATCH_PARENT );
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
blockView.setLayoutParams(params);
addContentView(blockView, params);
blockView.animate().translationX(500).setDuration(3000).start();  // animation

This is x-axis slide animation. set x width and duration.
start is start animation

There are a lot of methods which are related with animation.
The list is Android Developer

Hardware Accelerator

Use withLayer() instead of start(). This API is valid after 14.

blockView.animate().translationX(400).setDuration(3000).withLayer();

Double

If you want to add animation after finishing animation.
Use withEndAction.

blockView.animate().translationX(400).setDuration(3000).withEndAction(new Runnable() {	
			@Override
			public void run() {
                   		blockView.animate().translationX(-400).setDuration(3000).start();
			}
		});

Ref

Android Developer