How can I draw circle between two points using the Android SDK?
Asked
Active
Viewed 3.1k times
2 Answers
40
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:
Bitmap bmp = Bitmap.createBitmap(width, height, config);
Draw on the bitmap canvas
Canvas c = new Canvas(bmp);
c.drawCircle(cx, cy, radius, paint)
setting to imageview
img.setBackgroundDrawable(new BitmapDrawable(bmp));

Hazem Farahat
- 3,790
- 2
- 26
- 42
12
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:
public class Circle extends SurfaceView implements SurfaceHolder.Callback {
private Paint paint;
public void onDraw(Canvas canvas) {
canvas.drawCircle(x, y, radius, this.paint);
}
}
Then you can add the SurfaceView to your Activity class like:
public class MovingCircle extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new Circle());
}
}
I hope this will also help you.

Andro Selva
- 53,910
- 52
- 193
- 240

Monte
- 121
- 1
- 3