fade Out View with ViewPropertyAnimatorListener - Android Animation

Android examples for Animation:Fade Animation

Description

fade Out View with ViewPropertyAnimatorListener

Demo Code


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 fadeOutView(View view) {
        fadeOutView(view, ANIMATION_DURATION_SHORT);
    }/*from   w  w w.  j  a  v a2s.co m*/
    public static void fadeOutView(View view, int duration) {
        fadeOutView(view, duration, null);
    }
    public static void fadeOutView(View view, int duration,
            final AnimationListener listener) {
        ViewCompat.animate(view).alpha(0f).setDuration(duration)
                .setListener(new ViewPropertyAnimatorListener() {
                    @Override
                    public void onAnimationStart(View view) {
                        if (listener == null
                                || !listener.onAnimationStart(view)) {
                            //execute Parent MEthod
                            view.setDrawingCacheEnabled(true);
                        }
                    }

                    @Override
                    public void onAnimationEnd(View view) {
                        if (listener == null
                                || !listener.onAnimationEnd(view)) {
                            //execute Parent MEthod
                            view.setVisibility(View.GONE);
                            //view.setAlpha(1f);
                            view.setDrawingCacheEnabled(false);
                        }
                    }

                    @Override
                    public void onAnimationCancel(View view) {
                        if (listener == null
                                || !listener.onAnimationCancel(view)) {
                            //execute Parent MEthod
                        }
                    }
                });
    }
}

Related Tutorials