触摸图片的Android位置

时间:2014-01-20 17:36:48

标签: android zoom zooming pinchzoom image-zoom

我是Android编程的新手并且遇到了很大的问题。

我正在缩放图片并滚动它。然后用户必须触摸一个点。如何根据缩放的图片获得触摸点? (x& y值从图片的左上角开始。)

缩放和滚动工作正常。

@Override
        public boolean onTouch(View v, MotionEvent event) {
             myImageView.mScaleDetector.onTouchEvent(event);
             myImageView.mGestureDetector.onTouchEvent(event);
            PointF curr = new PointF(event.getX(), event.getY());

            if (myImageView.state == NONE || myImageView.state == DRAG
                    || myImageView.state == FLING) {
                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    last.set(curr);
                    if (myImageView.fling != null)
                        myImageView.fling.cancelFling();
                    myImageView.setState(DRAG);
                    break;

                case MotionEvent.ACTION_MOVE:
                    if (myImageView.state == DRAG) {
                        deltaX = curr.x - last.x;
                        deltaY = curr.y - last.y;
                        fixTransX = myImageView.getFixDragTrans(deltaX,
                                myImageView.viewWidth,
                                myImageView.getImageWidth());
                        fixTransY = myImageView.getFixDragTrans(deltaY,
                                myImageView.viewHeight,
                                myImageView.getImageHeight());
                        myImageView.matrix.postTranslate(fixTransX,
                                fixTransY);
                        myImageView.fixTrans();
                        last.set(curr.x, curr.y);
                    }
                    break;

                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_POINTER_UP:
                    myImageView.setState(NONE);
                    break;
                }

我正在使用Michael Ortiz的TouchImageView。在Github上找到它。

我需要一个类似于Objective C(iPhone SDK)中的CGPoint pos = [recognizer locationInView: map]的方法

br Stone

0 个答案:

没有答案