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

Apps Draw on canvas (SurfaceView)

hollowback

Lurker
Nov 12, 2009
5
0
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?
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones