安卓(Android) 怎么交叉两个视图(View)的动画(Animation),显示一个,另一个隐藏

2019年10月16日23:31:57安卓(Android) 怎么交叉两个视图(View)的动画(Animation),显示一个,另一个隐藏已关闭评论 410 1363字阅读4分32秒

1.简介

安卓(Android) 怎么交叉两个视图(View)的动画(Animation),显示一个,另一个隐藏?——请看下文。

2.示例代码

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



import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorListener;
import android.view.View;

public class Main {
    public static final int ANIMATION_DURATION_SHORTEST = 150;
    public static final int ANIMATION_DURATION_SHORT = 250;

    public static void crossFadeViews(View showView, View hideView) {
        crossFadeViews(showView, hideView, ANIMATION_DURATION_SHORT);
    }

    public static void crossFadeViews(View showView, final View hideView,
            int duration) {
        fadeInView(showView, duration);
        fadeOutView(hideView, duration);
    }

    public static void fadeInView(View view) {
        fadeInView(view, ANIMATION_DURATION_SHORTEST);
    }

    public static void fadeInView(View view, int duration) {
        view.setVisibility(View.VISIBLE);
        view.setAlpha(0f);

        
        ViewCompat.animate(view).alpha(1f).setDuration(duration)
                .setListener(null);
    }
    public static void fadeOutView(View view) {
        fadeOutView(view, ANIMATION_DURATION_SHORTEST);
    }
    public static void fadeOutView(final View view, int duration) {
        ViewCompat.animate(view).alpha(0f).setDuration(duration)
                .setListener(new ViewPropertyAnimatorListener() {
                    @Override
                    public void onAnimationStart(View view) {
                        view.setDrawingCacheEnabled(true);
                    }

                    @Override
                    public void onAnimationEnd(View view) {
                        view.setVisibility(View.GONE);
                        view.setAlpha(1f);
                        view.setDrawingCacheEnabled(false);
                    }

                    @Override
                    public void onAnimationCancel(View view) {
                    }
                });
    }
}

 
继续阅读