Draw circle Android basic example

Canvas, drawCircle(), Paint, onDraw(), setStrokeWidth(), setStyle()

public class MainActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}
 
	private static class SampleView extends View {
 
		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);
 
		}
 
		@Override
		protected void onDraw(Canvas canvas) {
 
			canvas.drawColor(Color.CYAN);
			Paint p = new Paint();
			// smooths
			p.setAntiAlias(true);
			p.setColor(Color.RED);
			p.setStyle(Paint.Style.STROKE); 
			p.setStrokeWidth(4.5f);
			// opacity
			//p.setAlpha(0x80); //
			canvas.drawCircle(50, 50, 30, p);
		}
 
	}
}
This entry was posted in Android Examples Code, Bitmap, drawing and tagged , , . Bookmark the permalink.


Comments are closed.

34,008 views