Android examples for Animation:Fade Animation
fade In View with ViewPropertyAnimatorListener
import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewPropertyAnimatorListener; import android.view.View; public class Main{ public static final int ANIMATION_DURATION_SHORT = 150; public static void fadeInView(View view) { fadeInView(view, ANIMATION_DURATION_SHORT); }// ww w. java 2s. c om public static void fadeInView(View view, int duration) { fadeInView(view, duration, null); } public static void fadeInView(View view, int duration, final AnimationListener listener) { view.setAlpha(0f); view.setVisibility(View.VISIBLE); ViewPropertyAnimatorListener vpListener = null; if (listener != null) { vpListener = new ViewPropertyAnimatorListener() { @Override public void onAnimationStart(View view) { if (!listener.onAnimationStart(view)) { //execute Parent MEthod view.setDrawingCacheEnabled(true); } } @Override public void onAnimationEnd(View view) { if (!listener.onAnimationEnd(view)) { //execute Parent MEthod view.setDrawingCacheEnabled(false); } } @Override public void onAnimationCancel(View view) { if (!listener.onAnimationCancel(view)) { //execute Parent MEthod } } }; } ViewCompat.animate(view).alpha(1f).setDuration(duration) .setListener(vpListener); } }