上滑消失下滑显示效果时的动画效果

写一个动画类

public class AnimatorUtil {

    private static LinearOutSlowInInterpolator FAST_OUT_SLOW_IN_INTERPOLATOR = new LinearOutSlowInInterpolator();

    private static AccelerateInterpolator LINER_INTERPOLATOR = new AccelerateInterpolator();

    //包含缩放和平移

    // 显示view
    public static void scaleShow(View view, ViewPropertyAnimatorListener viewPropertyAnimatorListener) {
        view.setVisibility(View.VISIBLE);
        ViewCompat.animate(view)
                .scaleX(1.0f)
                .scaleY(1.0f)
                .alpha(1.0f)
                .setDuration(800)
                .setListener(viewPropertyAnimatorListener)
                .setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR)
                .start();
    }

    // 隐藏view
    public static void scaleHide(View view, ViewPropertyAnimatorListener viewPropertyAnimatorListener) {
        ViewCompat.animate(view)
                .scaleX(0.0f)
                .scaleY(0.0f)
                .alpha(0.0f)
                .setDuration(800)
                .setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR)
                .setListener(viewPropertyAnimatorListener)
                .start();
    }

    // 显示view
    public static void translateShow(View view, ViewPropertyAnimatorListener viewPropertyAnimatorListener) {
        view.setVisibility(View.VISIBLE);
        ViewCompat.animate(view)
                .translationY(0)
                .setDuration(400)
                .setListener(viewPropertyAnimatorListener)
                .setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR)
                .start();
    }

    // 隐藏view
    public static void translateHide(View view, ViewPropertyAnimatorListener viewPropertyAnimatorListener) {
        view.setVisibility(View.VISIBLE);
        ViewCompat.animate(view)
                .translationY(360)
                .setDuration(400)
                .setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR)
                .setListener(viewPropertyAnimatorListener)
                .start();
    }
}

2.

当想让其隐藏时调用  img代表控件   isclick表示目前是否在显示,用于显示隐藏的判断条件里

AnimatorUtil.translateHide(img, new StateListener() {
    @Override
    public void onAnimationStart(View view) {
        super.onAnimationStart(view);
        isclick = true;   
    }
});

显示时

AnimatorUtil.translateShow(img, new StateListener() {
    @Override
    public void onAnimationStart(View view) {
        super.onAnimationStart(view);
        isclick = false;
    }
});

所用参数  

private boolean isAnimateIng = false;   用于显示隐藏的判断条件里,就是等动画状态

class StateListener implements ViewPropertyAnimatorListener {
    @Override
    public void onAnimationStart(View view) {
        isAnimateIng = true;
    }

    @Override
    public void onAnimationEnd(View view) {
        isAnimateIng = false;
    }

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

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页