Android examples for Animation:Alpha Fly Animation
Start an alpha animation from given opacity to given one
//package com.java2s; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.Interpolator; public class Main { /**// w w w .j av a 2 s . c om * Start an alpha animation from given opacity to given one * * @param target * : Target object to apply alpha animation * @param from * : Float value to determine opacity at the beginning * @param to * : Float value to determine opacity at the end * @param duration * : Animation duration */ public static void StartAlpha(View target, float from, float to, int duration) { target.clearAnimation(); target.startAnimation(Alpha(from, to, duration)); } /** * Start an alpha animation from given opacity to given one with * interpolation, but without callback * * @param target * : Target object to apply alpha animation * @param from * : Float value to determine opacity at the beginning * @param to * : Float value to determine opacity at the end * @param duration * : Animation duration * @param interpolation * : Animation interpolation */ public static void StartAlpha(View target, float from, float to, int duration, Interpolator interpolation) { target.clearAnimation(); target.startAnimation(Alpha(from, to, duration, interpolation)); } /** * Start an alpha animation on target object from given opacity to given one * with interpolation and send callback to listener * * @param target * : Target object to apply alpha animation * @param from * : Float value to determine opacity at the beginning * @param to * : Float value to determine opacity at the end * @param duration * : Animation duration * @param interpolation * : Animation interpolation * @param listener * : Animation listener to send callback */ public static void StartAlpha(View target, float from, float to, int duration, Interpolator interpolation, AnimationListener listener) { target.clearAnimation(); target.startAnimation(Alpha(from, to, duration, interpolation, listener)); } /** * Returns an alpha animation from given opacity to given one * * @param from * : Float value to determine opacity at the beginning * @param to * : Float value to determine opacity at the end * @param duration * : Animation duration */ public static Animation Alpha(float from, float to, int duration) { return Alpha(from, to, duration, null); } /** * Returns an alpha animation from given opacity to given one with * interpolation, but without callback * * @param from * : Float value to determine opacity at the beginning * @param to * : Float value to determine opacity at the end * @param duration * : Animation duration * @param interpolation * : Animation interpolation */ public static Animation Alpha(float from, float to, int duration, Interpolator interpolation) { return Alpha(from, to, duration, interpolation, null); } /** * Returns an alpha animation on target object from given opacity to given * one with interpolation and send callback to listener * * @param from * : Float value to determine opacity at the beginning * @param to * : Float value to determine opacity at the end * @param duration * : Animation duration * @param interpolation * : Animation interpolation * @param listener * : Animation listener to send callback */ public static Animation Alpha(float from, float to, int duration, Interpolator interpolation, AnimationListener listener) { AlphaAnimation animation = new AlphaAnimation(from, to); animation.setDuration(duration); if (interpolation != null) animation.setInterpolator(interpolation); if (listener != null) { animation.setAnimationListener(listener); } return animation; } }