Android examples for Animation:Slide Animation
slide Animation
//package com.java2s; import android.content.Context; import android.view.View; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationSet; import android.view.animation.AnimationUtils; 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 slideAnimation(Context context, View view, final int ANIM_TYPE_ID) { Animation rightAnimation = AnimationUtils.loadAnimation(context, ANIM_TYPE_ID);/* w ww. ja v a 2 s . c o m*/ rightAnimation.setAnimationListener(new AnimationListener() { public void onAnimationStart(Animation arg0) { } public void onAnimationRepeat(Animation arg0) { } public void onAnimationEnd(Animation arg0) { } }); view.startAnimation(rightAnimation); } 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) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { } }); } }