2

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;
}
BenG
  • 381
  • 3
  • 6
  • 14

2 Answers2

4

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?

Community
  • 1
  • 1
Kanak Sony
  • 1,937
  • 1
  • 23
  • 37
  • I want solid circle not with white space inside – BenG Jun 04 '14 at 13:36
  • Check PaintStyle API, for different available styles http://developer.android.com/reference/android/graphics/Paint.Style.html You should try here FILL and FILL_AND_STROKE. – Kanak Sony Jun 04 '14 at 13:39
1

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

Arman Manucharyan
  • 227
  • 1
  • 4
  • 18