To draw a circle using paint
, you need to create a custom view like this
private class CircleView extends View{
Paint paint = new Paint();
public CircleView(Context context) {
super(context);
}
@Override
public void onDraw(Canvas canvas) {
paint.setColor(Color.GREEN);
// set your own position and radius
canvas.drawCircle(100,200,100,paint);
}
}
And, then add an Parent Layout to the Activity
RelativeLayout relativeLayout = new RelativeLayout(this);
relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
setContentView(relativeLayout);
Finally you need to add the circle view
to the Parent Layout
relativeLayout.addView(new CircleView(this));
Another way is to create the circle as drawable xml
and set it to an ImageView
Create a circle.xml in drawable/
And then , set the drawable in ImageView
in your layout
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/circle"/>