Android examples for Animation:Scale Animation
Custom Scale Animation
//package com.java2s; import android.view.View; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationSet; import android.view.animation.RotateAnimation; import android.view.animation.ScaleAnimation; import android.view.animation.TranslateAnimation; public class Main { private int randomNumberAnimation = 0; public static void CustomScaleAnimation(View view) { view.setVisibility(View.VISIBLE); AnimationSet set = new AnimationSet(true); set.setFillAfter(true);//from w ww . j a va 2 s. c o m set.setDuration(700); ScaleAnimation scaleAnimation = new ScaleAnimation(.0f, 1f, .0f, 1f, Animation.RELATIVE_TO_SELF, (float) 0.5, Animation.RELATIVE_TO_SELF, (float) 0.5); set.addAnimation(scaleAnimation); view.startAnimation(set); } public void startAnimation(final View imageView, float translateFromDeltaX, float translatetodeltaX, float rotateFromDegree, float rotateToDegree, final int i) { imageView.setVisibility(View.VISIBLE); AnimationSet set = new AnimationSet(true); set.setFillAfter(true); set.setDuration(500); TranslateAnimation transX = new TranslateAnimation( translateFromDeltaX, translatetodeltaX, 0, 0); transX.setStartOffset(0); transX.setFillAfter(true); RotateAnimation an = new RotateAnimation(rotateFromDegree, rotateToDegree, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); an.setRepeatCount(0); an.setFillAfter(false); ScaleAnimation scaleAnimation = new ScaleAnimation(.0f, 1f, .0f, 1f, Animation.RELATIVE_TO_SELF, (float) 0.5, Animation.RELATIVE_TO_SELF, (float) 0.5); switch (randomNumberAnimation) { case 0: set.addAnimation(an); set.addAnimation(transX); set.addAnimation(scaleAnimation); break; case 1: set.addAnimation(scaleAnimation); break; } imageView.startAnimation(set); set.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation animation) { } }); } }