轻触一次即可移动,双指轻松调整图像视图的大小

时间:2018-09-07 09:49:14

标签: android image-resizing ontouchlistener multi-touch

我想单点触摸来移动对象(“图像视图”矩形)并用双指来调整图像大小

尝试:

rect.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            ViewGroup.LayoutParams lp = rect.getLayoutParams();
            float lasty = 0f;
            float lastx = 0f;
            final float distheight = event.getRawY() - lasty;
            final float distwidth = event.getRawX() - lastx;

            Log.d("MotionTouch:", "finger: " + event.getPointerCount());

            switch (event.getAction() & MotionEvent.ACTION_MASK) {
                case MotionEvent.ACTION_DOWN:
                    Log.d("MotionTouch:","ACTION_DOWN");
                    dx = v.getX() - event.getRawX();
                    dy = v.getY() - event.getRawY();
                    lastAction = MotionEvent.ACTION_DOWN;
                    break;

                case MotionEvent.ACTION_MOVE:
                    Log.d("MotionTouch:","ACTION_MOVE");
                    v.animate().x(event.getRawX() + dx).y(event.getRawY() + dy).setDuration(0).start();
                    break;


                case MotionEvent.ACTION_POINTER_DOWN:

                    Log.d("MotionTouch:","ACTION_POINTER_DOWN");
                    lp.height -= distheight;
                    lp.width -= distwidth;
                    rect.setLayoutParams(lp);
                    break;

                case MotionEvent.ACTION_POINTER_UP:
                    Log.d("MotionTouch:","ACTION_POINTER_UP");
                    lp.height += distheight;
                    lp.width += distwidth;
                    rect.setLayoutParams(lp);
                    break;

                default:

                    return true;
            }

           /* v.invalidate();
            v.requestLayout();*/
            return true;
        }
    });

它可以工作,但是当两根手指触摸(MotionEvent.ACTION_POINTER_DOWN情况下,然后隐藏)时,它会隐藏图像视图(矩形)

为什么隐藏触摸对象(ImageView rect)

rect是矩形图像视图。

0 个答案:

没有答案