在我的应用程序中,我想绘制一些几何形状,如圆形,矩形。当我拖动时,应该如图所示绘制圆圈。当我选择圆圈时,我应该能够移动并调整圆形大小。根据我的要求查看图片。现在我只能画圆圈了。如何在圆圈周围获得缩放框?帮助我。
@覆盖 public boolean onTouchEvent(MotionEvent event){
boolean handled = false;
int pointerId;
int actionIndex = event.getActionIndex();
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
clearCirclePointer();
mStartX = (int) event.getX();
mStartY = (int) event.getY();
break;
case MotionEvent.ACTION_MOVE:
pointerId = event.getPointerId(actionIndex);
mMidPointX = (int) ((event.getX() + mStartX) / 2);
mMidPointY = (int) ((event.getY() + mStartY) / 2);
mRadius = (int) Math.sqrt((Math.pow(mMidPointX - mStartX, 2) + Math.pow(mMidPointY - mStartY, 2)));
mPaint.setPathEffect(dashPath);
invalidate();
handled = true;
break;
case MotionEvent.ACTION_UP:
mEndX = (int) event.getX();
mEndY = (int) event.getY();
mMidPointX = ((mEndX + mStartX) / 2);
mMidPointY = ((mEndY + mStartY) / 2);
mRadius = (int) Math.sqrt((Math.pow(mMidPointX - mStartX, 2) + Math.pow(mMidPointY - mStartY, 2)));
mPaint.setPathEffect(solidPath);
mCircle.setxAxis(mMidPointX);
mCircle.setyAxis(mMidPointY);
mCircle.setRadius(mRadius);
mCircle.setPaint(mPaint);
mCirclePointer.put(event.getPointerId(0), mCircle);
invalidate();
break;
case MotionEvent.ACTION_CANCEL:
handled = true;
break;
default:
break;
}
return super.onTouchEvent(event) || handled;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
for (Circle circle : mCircleSet) {
if (mCircleSet == null || mCircleSet.size() == 0)
return;
canvas.drawCircle(circle.getxAxis(), circle.getyAxis(), circle.getRadius(), circle.getPaint());
}
}