hi am new to android platform in my code only dragging is happening and zooming not occurs please help me
这是使用代码的代码
@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;
}
这是我用过的 在线拖线和触摸活动的方法
帮帮我...