当缩放和拖动imageview android的图像时,x和y坐标

时间:2012-04-12 11:18:06

标签: android coordinates motion-detection image-zoom

您好, 这是我的缩放和拖动图像的代码。现在我想在触摸缩放图像时添加图像但我 没有得到准确的x和y坐标

请帮助我解释代码中缺少的内容。

View.OnTouchListener mTouchListener = new OnTouchListener() {

    public boolean onTouch(View v, MotionEvent event) {

    ImageView view = (ImageView) v;
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:

            savedMatrix.set(matrix);
            start.set(event.getX(), event.getY());
            Log.d(TAG, "mode=DRAG");
            mode = DRAG;

            if (flag) {     
//When mark button click then flag is true means add another image to display image when touch

                mImageView.setImageBitmap(combineImages(mSave, mIcon, event.getX(),
                        event.getY()));
                mSave = combineImages(mSave, mIcon, event.getX(), event.getY());
            }
            break;
        case MotionEvent.ACTION_POINTER_DOWN:

            oldDist = spacing(event);
            if (oldDist > 10f) {
                savedMatrix.set(matrix);
                midPoint(mid, event);
                mode = ZOOM;
                Log.d(TAG, "mode=ZOOM");
            }
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
            mode = NONE;
            Log.d(TAG, "mode=NONE");
            break;
        case MotionEvent.ACTION_MOVE:
            if (mode == DRAG) {
                matrix.set(savedMatrix);
                matrix.postTranslate(event.getX() - start.x, event.getY()
                        - start.y);

            } else if (mode == ZOOM) {

                float newDist = spacing(event);
                if (newDist > 10f) {
                    matrix.set(savedMatrix);
                    scale = newDist / oldDist;
                    matrix.postScale(scale, scale, mid.x, mid.y);
                }
            }
            break;
        }
        view.setImageMatrix(matrix);
        return true;
    }
};

我也提到this link,但不能理解更多......

请告诉我我做错了什么。

0 个答案:

没有答案