Draw a circle in android

How can I draw a circle between two points using android SDK?

+8
android
source share
2 answers

Create a bitmap, then draw it on the canvas, and then add that bitmap to the image or button or whatever you want.

Create a bitmap:

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

Draw a raster image canvas

  Canvas c = new Canvas(bmp); c.drawCircle(cx, cy, radius, paint) 

to view images

  img.setBackgroundDrawable(new BitmapDrawable(bmp)); 
+39
source share

You do not have to create a raster guide.

For example, if you use SurfaceView, in the SurfaceView class you can 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 a SurfaceView to your Activity class, for example:

 public class MovingCircle extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Circle()); } } 

I hope this also helps you.

+12
source share

All Articles