How can I draw circle between two points using the Android SDK?
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));
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With