Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw circle in android [closed]

Tags:

android

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

like image 569
Manisha Avatar asked Jun 01 '11 11:06

Manisha


2 Answers

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));
like image 71
Hazem Farahat Avatar answered Oct 18 '22 15:10

Hazem Farahat


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.

like image 40
Monte Avatar answered Oct 18 '22 14:10

Monte