Draw color line set stroke width Android basic example

Canvas, drawLine(), setStrokeWidth(), Paint, setAntiAlias(boolean), onDraw()

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.YELLOW);
			Paint p = new Paint();
			// smooths
			p.setAntiAlias(true);
			p.setColor(Color.RED);
			p.setStrokeWidth(4.5f);
			// opacity
			p.setAlpha(0x80); //
			// drawLine (float startX, float startY, float stopX, float stopY,
			// Paint paint)
			canvas.drawLine(0, 0, 40, 40, p);
			canvas.drawLine(40, 0, 0, 40, p);
 
		}
 
	}
}
This entry was posted in Android Examples Code, Bitmap, drawing and tagged , , . Bookmark the permalink.


Comments are closed.



22,445 views