安卓(Android) 怎么通过Alpha动画(Animation)让视图(View)不可见

2019年10月16日23:15:42安卓(Android) 怎么通过Alpha动画(Animation)让视图(View)不可见已关闭评论 350 2391字阅读7分58秒

1.简介

安卓(Android) 怎么通过Alpha动画(Animation)让视图(View)不可见?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

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{
    
    public static void invisibleViewByAlpha(final View view,
            long durationMillis, final boolean isBanClick,
            final AnimationListener animationListener) {
        if (view.getVisibility() != View.INVISIBLE) {
            view.setVisibility(View.INVISIBLE);
            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 invisibleViewByAlpha(final View view,
            long durationMillis, final AnimationListener animationListener) {
        invisibleViewByAlpha(view, durationMillis, false, animationListener);
    }
    
    public static void invisibleViewByAlpha(final View view,
            long durationMillis, boolean isBanClick) {
        invisibleViewByAlpha(view, durationMillis, isBanClick, null);
    }
    
    public static void invisibleViewByAlpha(final View view,
            long durationMillis) {
        invisibleViewByAlpha(view, durationMillis, false, null);
    }
    
    public static void invisibleViewByAlpha(final View view,
            boolean isBanClick, final AnimationListener animationListener) {
        invisibleViewByAlpha(view,
                AnimationUtil.DEFAULT_ANIMATION_DURATION, isBanClick,
                animationListener);
    }
    
    public static void invisibleViewByAlpha(final View view,
            final AnimationListener animationListener) {
        invisibleViewByAlpha(view,
                AnimationUtil.DEFAULT_ANIMATION_DURATION, false,
                animationListener);
    }
    
    public static void invisibleViewByAlpha(final View view,
            boolean isBanClick) {
        invisibleViewByAlpha(view,
                AnimationUtil.DEFAULT_ANIMATION_DURATION, isBanClick, null);
    }
    
    public static void invisibleViewByAlpha(final View view) {
        invisibleViewByAlpha(view,
                AnimationUtil.DEFAULT_ANIMATION_DURATION, false, null);
    }
}

 
继续阅读
编程十万个怎么办