Android examples for Animation:Animation Creation
Applies a specific animation for transitioning to a new Screen.
// Copyright 2009-2011 Google, All Rights reserved import android.app.Activity; import android.util.Log; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.TranslateAnimation; public class Main{ /**/* w w w .j a va 2 s.c om*/ * Applies a specific animation for transitioning to a new * Screen. * * @param activity - the form which is calling another screen * @param animType - the animation type */ public static void ApplyOpenScreenAnimation(Activity activity, String animType) { if (animType == null) { return; } if (SdkLevel.getLevel() <= SdkLevel.LEVEL_DONUT) { Log.e("AnimationUtil", "Screen animations are not available on android versions less than 2.0."); return; } int enter = 0; int exit = 0; if (animType.equalsIgnoreCase("fade")) { enter = activity.getResources().getIdentifier("fadein", "anim", activity.getPackageName()); exit = activity.getResources().getIdentifier("hold", "anim", activity.getPackageName()); } else if (animType.equalsIgnoreCase("zoom")) { exit = activity.getResources().getIdentifier("zoom_exit", "anim", activity.getPackageName()); enter = activity.getResources().getIdentifier("zoom_enter", "anim", activity.getPackageName()); } else if (animType.equalsIgnoreCase("slidehorizontal")) { exit = activity.getResources().getIdentifier("slide_exit", "anim", activity.getPackageName()); enter = activity.getResources().getIdentifier("slide_enter", "anim", activity.getPackageName()); } else if (animType.equalsIgnoreCase("slidevertical")) { exit = activity.getResources().getIdentifier("slide_v_exit", "anim", activity.getPackageName()); enter = activity.getResources().getIdentifier("slide_v_enter", "anim", activity.getPackageName()); } else if (animType.equalsIgnoreCase("none")) { // enter and exit are already set to 0, so // no animations will be played. } else { // Return here so overridePendingTransitions isn't run, and android // does it's default thing. return; } EclairUtil.overridePendingTransitions(activity, enter, exit); } }