Android通过手势实现的缩放处理
2010-07-01 15:25:00 来源:WEB开发网}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
float size = event.getSize();
int szi = (int) size;
int dxi = szi >> 12;
int dyit = ((1 << 12) - 1);
int dyi = szi & dyit;
DisplayMetrics metrics = getResources().getDisplayMetrics();
float dx = metrics.widthPixels * dxi / (float) dyit;
float dy = metrics.heightPixels * dyi / (float) dyit;
x1 = event.getX();
y1 = event.getY();
x2 = x1 + dx;
y2 = y1 + dy;
invalidate();
return true;
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
float r = (float) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2)
* (y1 - y2)) / 2;
r = 50 >= r ? 50 : r;
Paint paint = new Paint();
paint.setColor(Color.BLUE);
canvas.drawCircle(x1, y1, r, paint);
}
}
}
更多精彩
赞助商链接