1

こんにちは、私のコードでは Android プラットフォームが初めてです。ドラッグのみが発生し、ズームは発生しません。助けてください

ここに使用しているコードがあります

@Override
public void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub



    canvas.drawBitmap(image, getBounds().left,getBounds().top, new Paint());



}

/* (non-Javadoc)
 * @see com.simplogics.surfaceview.Views.BaseView#onTouchEvent(android.view.MotionEvent)
 */


static final int NONE = 0;
static final int DRAG = 1;
static final int ZOOM = 2;
int mode = NONE;


@Override

public boolean onTouchEvent(MotionEvent event) {
    boolean handled = false;

    Log.d("SimpEditText", "(int)event.getX() " + (int)event.getX());
    Log.d("SimpEditText", "(int)event.getY() " + (int)event.getY());

    if(isTouchedInBounds((int)event.getX(), (int)event.getY())){
        Log.d("SimpEditText", "Touched in Bounds");
        handled = true;
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            savedMatrix.set(matrix);
            start.set(event.getX(), event.getY());
            lastPosition.x = getBounds().left;
            lastPosition.y = getBounds().top;
        //  initialRotation = rotation(event);
            Log.d("VerticalLabelView", "mode=DRAG");
            mode = DRAG;
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            mode = ZOOM;

            initialScale = spacing(event);
            midPoint(mid, event);
            Log.d("VerticalLabelView", "mode=ZOOM");
            initialRotation = rotation(event);

            break;
        case MotionEvent.ACTION_UP:
            mode = NONE;
            break;
        case MotionEvent.ACTION_POINTER_UP:
            mode = NONE;
            Log.d("VerticalLabelView", "mode=NONE");
            break;
        case MotionEvent.ACTION_MOVE:
            if (mode == DRAG) {
                int x = (int)(event.getX() - start.x);
                int y = (int)(event.getY() - start.y);
                setPosition((int)lastPosition.x + x, (int)lastPosition.y + y);



            }else if(mode == ZOOM){

                currentScale = spacing(event);

                float scale =currentScale/initialScale;

                currentRotation = rotation(event);
                float angle = currentRotation - initialRotation;
                if(getImage().getWidth()> 100 && image.getWidth() <900){
                    /*Matrix testMatrix = new Matrix();
                    testMatrix.postScale(scale, scale,mid.x,mid.y);*/
                /*  rotatedImage = Bitmap.createBitmap(getImage(), 0, 0, (int)(image.getWidth()*scale),
                            (int)(image.getHeight()*scale), testMatrix, true);
                */
                    rotatedImage = Bitmap.createScaledBitmap(getImage(), (int)(image.getWidth()*scale), 
                        (int)(image.getHeight()*scale), true);
                setScale(getBounds().left,getBounds().top
                        , (int)(getImage().getWidth()*scale), (int)(getImage().getHeight()*scale));

                /*rotatedImage =rotate(angle, image);
                Matrix testMatrix = new Matrix();
                testMatrix.postScale(scale, scale,mid.x,mid.y);
                this.image = rotatedImage;
                rotatedImage = Bitmap.createScaledBitmap(image, (int)(image.getWidth()*scale), 
                        (int)(image.getHeight()*scale), true);
                this.image = rotatedImage;*/
                /*Matrix testMatrix = new Matrix();
                testMatrix.postScale(scale, scale,mid.x,mid.y);*/
            //  this.image = rotatedImage;
                /*rotatedImage = Bitmap.createScaledBitmap(image, (int)(image.getWidth()*scale), 
                        (int)(image.getHeight()*scale), true);
                this.image = rotatedImage;*/
                }

                this.image = rotatedImage;
            }
            break;
        }


    }


    return handled;

}

これは私が使用した onDraw と touchevent メソッドです

私を助けてください...

4

1 に答える 1

0

このチュートリアルを試して、問題がどこにあるかを見つけてください。

このチュートリアルでは、次のような多くの機能を学習できます。

  1. 画像をドラッグ
  2. ピンチズーム(2本指)でズームイン
  3. ピンチズームでズームアウト(2本指)

それがあなたが探しているものであることを願っています

于 2012-05-28T13:17:56.630 に答える