Draw Path drawPath draw the trajectory of shot Android basic example

Draw the trajectory of shot.

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);
 
		}
	       private static void makePath(Path p) {
	            p.moveTo(10, 0);
	            p.cubicTo(100, -50, 200, 150, 300, 0);
	        }
		@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);
 
			p.setColor(Color.BLACK);
			Path mPath = new Path();
            makePath(mPath);
			canvas.drawPath(mPath, p); //(rectF, 90, 45, true, p);
		}
 
	}
}
This entry was posted in Android Examples Code, Bitmap, drawing and tagged , . Bookmark the permalink.


Comments are closed.

9,144 views