安卓(Android) 怎么启动淡出动画(Animation)

2019年10月15日20:40:16安卓(Android) 怎么启动淡出动画(Animation)已关闭评论 181 1189字阅读3分57秒

1.简介

安卓(Android) 怎么启动淡出动画(Animation)?——请看下文。

2.示例代码

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



import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;

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

    public static void startFadeOutAnimationOn(final View container) {
        startFadeOutAnimationOn(container, false);
    }

    public static void startFadeOutAnimationOn(final View container,
            boolean forceFade) {
        if (forceFade || container.getVisibility() == View.VISIBLE) {
            Animation animation = getFadeOutAnimation(FADE_DURATION);
            animation.setAnimationListener(new AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    container.setVisibility(View.GONE);
                }
            });

            container.startAnimation(animation);
        }
    }

    public static Animation getFadeOutAnimation(int durationInMilliseconds) {
        Animation fadeOut = new AlphaAnimation(1, 0);
        fadeOut.setFillAfter(true);
        fadeOut.setInterpolator(new AccelerateInterpolator());
        fadeOut.setDuration(durationInMilliseconds);
        return fadeOut;
    }
}

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