问题
how to draw full circle or point with canvas? I using canvas and path + paint classes
my code:
@Override
public boolean onTouchEvent(MotionEvent event) {
float eventX = event.getX();
float eventY = event.getY();
System.out.println(event.getAction());
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(eventX, eventY);
return true;
case MotionEvent.ACTION_MOVE:
path.lineTo(eventX, eventY);
break;
case MotionEvent.ACTION_UP:
path.addCircle(eventX, eventY, .1F, Path.Direction.CW);
break;
default:
return false;
}
// Schedules a repaint.
invalidate();
return true;
}
回答1:
You can draw Circle by overriding onDraw()
of your custom view. Check following link for drawing basics -
http://developer.android.com/training/custom-views/custom-drawing.html
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(x, y, radius, paint);
}
Also, similar replies are here - How to draw circle by canvas in Android?
回答2:
Your paint must be "full", for that you must write this
paint.setStyle(Paint.Style.FILL);
then just draw your circle
canvas.drawCircle(x, y, radius, paint);
I hope it will be helpfull
来源:https://stackoverflow.com/questions/24038730/android-draw-point