Draw Arc Android basic example

drawArc(), Canvas, Paint, 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(5);
			// opacity
			//p.setAlpha(0x80); //
 
			RectF rectF = new RectF(50, 20, 100, 80);
			canvas.drawOval(rectF, p);
			p.setColor(Color.BLACK);
			canvas.drawArc (rectF, 90, 45, true, p);
		}
 
	}
}
This entry was posted in Android Examples Code, Bitmap, drawing and tagged , . Bookmark the permalink.


Comments are closed.

35,170 views