Android 控件点击缩放动画

    //手指离开屏幕时还原
    public static void addScaleTouch(View view) {
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN://收缩到0.96(正常值是1),速度50
                        view.animate().scaleX(0.96f).scaleY(0.96f).setDuration(50).start();
                        break;
                    case MotionEvent.ACTION_UP:
                        view.animate().scaleX(1).scaleY(1).setDuration(50).start();
                        break;
                }
                return false;
            }
        });
    }

    //自动还原
    public static void addScaleTouch2(View view) {
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN://收缩到0.96(正常值是1),速度50
                        view.animate().scaleX(0.96f).scaleY(0.96f).setDuration(50).start();
                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                if (view != null)
                                    view.animate().scaleX(1).scaleY(1).setDuration(50).start();
                            }
                        }, 500);
                        break;
                    case MotionEvent.ACTION_UP:
                        view.animate().scaleX(1).scaleY(1).setDuration(50).start();
                        break;
                }
                return false;
            }
        });
    }
posted @ 2022-04-14 09:31  指切  阅读(244)  评论(0编辑  收藏  举报