我正在使用手指移动在 android 画布中绘制闭合路径。这是我的代码
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
startPoint = new PointF(event.getX(), event.getY());
endPoint = new PointF();
hotSpot = new HotSpots();
endPoint.x = event.getX();
endPoint.y = event.getY();
wallpath = new Path();
wallpath.moveTo(endPoint.x,endPoint.y);
break;
case MotionEvent.ACTION_MOVE:
PointF point = new PointF(event.getX(),event.getY());
endPoint.x = event.getX();
endPoint.y = event.getY();
invalidate();
break;
case MotionEvent.ACTION_UP:
endPoint.x = startPoint.x;//event.getX();
isFinished = true;
break;
default:
break;
}
@Override
protected void onDraw(Canvas canvas)
{
wallpath.lineTo(endPoint.x, endPoint.y);
canvas.drawPath(wallpath, paint);
if(isFinished)
{
wallpath.lineTo(endPoint.x, endPoint.y);
canvas.drawPath(wallpath, paint);
}
}
在每一次新的接触中,我都在创造一条新的道路。但是,当绘制新路径时,旧路径会被删除。如何在画布上绘制多个路径,每个路径具有不同的填充颜色。