Skip to content Skip to sidebar Skip to footer

Draw Circle In Android

How can I draw circle between two points using the Android SDK?

Solution 1:

Create A bitmap then draw on its canvas and then add this bitmap to an imageview or button or whatever you want.

Create A bitmap:

Bitmapbmp= Bitmap.createBitmap(width, height, config);

Draw on the bitmap canvas

Canvasc=newCanvas(bmp);
    c.drawCircle(cx, cy, radius, paint)

setting to imageview

    img.setBackgroundDrawable(newBitmapDrawable(bmp));

Solution 2:

You don't necessarily need to create a bitmap manual.

For example if you use a SurfaceView, in the SurfaceView class you are able to draw a circle:

publicclassCircleextendsSurfaceViewimplementsSurfaceHolder.Callback {
private Paint paint;

    publicvoidonDraw(Canvas canvas) {
        canvas.drawCircle(x, y, radius, this.paint);
    }
}

Then you can add the SurfaceView to your Activity class like:

publicclassMovingCircleextendsActivity {

    @OverridepublicvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(newCircle());
    }

}

I hope this will also help you.

Post a Comment for "Draw Circle In Android"