alpha Hide ObjectAnimator - Android android.animation

Android examples for android.animation:ObjectAnimator

Description

alpha Hide ObjectAnimator

Demo Code


//package com.java2s;
import android.animation.Animator;

import android.animation.ObjectAnimator;

import android.support.annotation.NonNull;

import android.view.View;

public class Main {
    public static final int DURATION_SHORT = 300;

    public static void alphaHide(@NonNull final View view,
            final Runnable rWhenDone) {
        alphaHide(view, DURATION_SHORT, rWhenDone);
    }/*from w  w  w.ja va 2  s.  c o m*/

    public static void alphaHide(@NonNull final View view, long duration,
            final Runnable rWhenDone) {
        if (view.getWindowToken() == null) {
            if (rWhenDone != null)
                rWhenDone.run();
            return;
        }
        ObjectAnimator alpha = ObjectAnimator
                .ofFloat(view, "alpha", 1f, 0f);
        alpha.setDuration(duration);
        alpha.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.INVISIBLE);
                if (rWhenDone != null)
                    rWhenDone.run();
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                view.setVisibility(View.INVISIBLE);
                if (rWhenDone != null)
                    rWhenDone.run();
            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        alpha.start();
    }
}

Related Tutorials