答案 0 :(得分:0)
创建custom view并覆盖onDraw(Canvas canvas)
方法,你必须draw your shape内的方式:
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(touched)
canvas.drawCircle(centerX, centerY, radius, mPaint);
}
然后在onTouchEvent
方法中处理手势:
@Override
public boolean onTouchEvent(MotionEvent e) {
float x = e.getX();
float y = e.getY();
switch (e.getAction()) {
case MotionEvent.ACTION_DOWN:
touched = true;
centerX = x;
centerY = y;
break;
case MotionEvent.ACTION_MOVE:
// calculate radius
radius = Math.abs(centerX - x);
break;
case (MotionEvent.ACTION_UP) :
touched = false;
break;
}
// call next frame
postInvalidate();
return true;
}
另见canvas.drawOval方法。