Hide a View by alpha animation - Android Animation

Android examples for Animation:Animation to Hide

Description

Hide a View by alpha animation

Demo Code


import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.CycleInterpolator;
import android.view.animation.TranslateAnimation;

public class Main{
    /*from  w  w w .  j  av a 2 s. co  m*/
    public static void goneViewByAlpha(final View view,
            long durationMillis, final boolean isBanClick,
            final AnimationListener animationListener) {
        if (view.getVisibility() != View.GONE) {
            view.setVisibility(View.GONE);
            AlphaAnimation hiddenAlphaAnimation = AnimationUtil
                    .getHiddenAlphaAnimation(durationMillis);
            hiddenAlphaAnimation
                    .setAnimationListener(new AnimationListener() {
                        @Override
                        public void onAnimationStart(Animation animation) {
                            if (isBanClick) {
                                view.setClickable(false);
                            }
                            if (animationListener != null) {
                                animationListener
                                        .onAnimationStart(animation);
                            }
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {
                            if (animationListener != null) {
                                animationListener
                                        .onAnimationRepeat(animation);
                            }
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            if (isBanClick) {
                                view.setClickable(true);
                            }
                            if (animationListener != null) {
                                animationListener.onAnimationEnd(animation);
                            }
                        }
                    });
            view.startAnimation(hiddenAlphaAnimation);
        }
    }
    
    public static void goneViewByAlpha(final View view,
            long durationMillis, final AnimationListener animationListener) {
        goneViewByAlpha(view, durationMillis, false, animationListener);
    }
    
    public static void goneViewByAlpha(final View view,
            long durationMillis, final boolean isBanClick) {
        goneViewByAlpha(view, durationMillis, isBanClick, null);
    }
    
    public static void goneViewByAlpha(final View view, long durationMillis) {
        goneViewByAlpha(view, durationMillis, false, null);
    }
    
    public static void goneViewByAlpha(final View view,
            final boolean isBanClick,
            final AnimationListener animationListener) {
        goneViewByAlpha(view, AnimationUtil.DEFAULT_ANIMATION_DURATION,
                isBanClick, animationListener);
    }
    
    public static void goneViewByAlpha(final View view,
            final AnimationListener animationListener) {
        goneViewByAlpha(view, AnimationUtil.DEFAULT_ANIMATION_DURATION,
                false, animationListener);
    }
    
    public static void goneViewByAlpha(final View view,
            final boolean isBanClick) {
        goneViewByAlpha(view, AnimationUtil.DEFAULT_ANIMATION_DURATION,
                isBanClick, null);
    }
    
    public static void goneViewByAlpha(final View view) {
        goneViewByAlpha(view, AnimationUtil.DEFAULT_ANIMATION_DURATION,
                false, null);
    }
}

Related Tutorials