• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Draw on canvas (SurfaceView)

Hi, I'm trying to do easy app for draw on screen. I followed the tutorial on Graphics | Android Developers.
In my onTouchEvent method I have:
Code:
_canvas = holder.lockCanvas();
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			_path = new Path();
			_path.moveTo(event.getX(), event.getY());
			_path.lineTo(event.getX(), event.getY());
		} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
			_path.lineTo(event.getX(), event.getY());			
			_canvas.drawPath(_path, mPaint);
			_path = new Path();
			_path.moveTo(event.getX(), event.getY());
		} else if (event.getAction() == MotionEvent.ACTION_UP) {
			_path.lineTo(event.getX(), event.getY());
			_canvas.drawPath(_path, mPaint);
		}		
		holder.unlockCanvasAndPost(_canvas);
But when I draw, it shows something like that:

so I draw another lines and image changes to


In constructor of my MySurface class (which extends SurfaceView and implements SurfaceHolder.Callback) i set up holder variable:
Code:
		holder = getHolder();
		holder.addCallback(this);

Does anybody know what is wrong?
 
Have you tried running it on a physical device? Anything related to graphics tends to either work poorly or simply not work at all on the AVD.
 
Back
Top Bottom