android 双指缩放

img_round.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                // return ArtFilterActivity.this.mGestureDetector.onTouchEvent(event);
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    baseValue = 0;
                    float x = last_x = event.getRawX();
                    float y = last_y = event.getRawY();
                } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
                    if (event.getPointerCount() == 2) {
                        float x = event.getX(0) - event.getX(1);
                        float y = event.getY(0) - event.getY(1);
//                        float value = (float) Math.sqrt(x * x + y * y);// 计算两点的距离
                        float value = (float) x;// 计算x的距离
                        if (baseValue == 0) {
                            baseValue = value;
                        } else {
                            if (value - baseValue >= 10 || value - baseValue <= -10) {
                                float scale = value / baseValue;// 当前两点间的距离除以手指落下时两点间的距离就是需要缩放的比例。
                                Log.e("ddddddd",scale+"");  //缩放图片
                            }
                        }
                    } else if (event.getPointerCount() == 1) {
                        float x = event.getRawX();
                        float y = event.getRawY();
                        x -= last_x;
                        y -= last_y;
                        if (x >= 10 || y >= 10 || x <= -10 || y <= -10)
                            Log.e("移动图片位置", "移动图片位置"); //移动图片位置
                        last_x = event.getRawX();
                        last_y = event.getRawY();
                    }
                } else if (event.getAction() == MotionEvent.ACTION_UP) {

                }
                return true;
            }
        });

你可能感兴趣的:(app-android)