expand Fade Animation - Android Animation

Android examples for Animation:Fade Animation

Description

expand Fade Animation

Demo Code


import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
import android.view.inputmethod.InputMethodManager;
import java.util.List;

public class Main{
    public static final int DEFAULT_DURATION = -1;
    public static void expandFade(final View fadeIn, final View fadeOut,
            int durationMs, final List<AnimationCallback> animations) {
        fadeOut.setAlpha(1);/* w ww  . j  a  va  2  s  .  c  o  m*/
        ViewPropertyAnimator animator = fadeOut.animate();
        animator.cancel();
        if (Build.VERSION.SDK_INT >= 16) {
            animator = animator.alpha(1).withLayer();
        } else {
            animator = animator.alpha(1);
        }
        animator.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                fadeIn.setVisibility(View.VISIBLE);
                fadeOut.setVisibility(View.GONE);
                for (int i = 0; i < animations.size(); i++) {
                    animations.get(i).onAnimationEnd(true);
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                super.onAnimationCancel(animation);
                for (int i = 0; i < animations.size(); i++) {
                    animations.get(i).onAnimationStart(true);
                }
            }

            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                for (int i = 0; i < animations.size(); i++) {
                    animations.get(i).onAnimationStart(true);
                }
            }
        });
        if (durationMs != DEFAULT_DURATION) {
            animator.setDuration(durationMs);
        }
        animator.start();
    }
}

Related Tutorials