Transitions alpha from 1 to 0 and then sets visibility to gone - Android Animation

Android examples for Animation:Alpha Fly Animation

Description

Transitions alpha from 1 to 0 and then sets visibility to gone

Demo Code


//package com.java2s;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.view.View;

public class Main {
    public static final int DEFAULT_FADE_DURATION = 200;

    /**//from  w w  w  .jav a 2  s.c om
     * Transitions alpha from 1 to 0 and then sets visibility to gone
     *
     * @param view
     * @param duration
     */
    public static void fadeOut(final View view, int duration) {
        ObjectAnimator anim = ObjectAnimator.ofFloat(view, "alpha", 1, 0);
        anim.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        anim.setDuration(DEFAULT_FADE_DURATION);
        anim.start();
    }

    /**
     * Fade out with default duration
     *
     * @param view
     */
    public static void fadeOut(View view) {
        fadeOut(view, DEFAULT_FADE_DURATION);
    }
}

Related Tutorials