安卓(Android) 怎么展开淡入淡出动画(Animation)

2019年10月15日20:42:23安卓(Android) 怎么展开淡入淡出动画(Animation)已关闭评论 344 1486字阅读4分57秒

1.简介

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

2.示例代码

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

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);
        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();
    }
}

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