1,105,395 Community Members

Need help with drawing on surface view in for android

Member Avatar
woodenduck
Light Poster
29 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I would like to create a notebook type application that will accept touch input and allow you to draw on the surface view. I'm unsure what I'm doing wrong since I have not programmed for the Android before.

Here is what I have:

findViewById(R.id.pageSurface).setOnTouchListener(new View.OnTouchListener() {

			public boolean onTouch(View v, MotionEvent event) {
				SurfaceHolder holder = ((SurfaceView)findViewById(R.id.pageSurface)).getHolder();
				Canvas canvas = holder.lockCanvas();
				Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
				
				paint.setColor(Color.BLACK);
				paint.setDither(true); 
				paint.setColor(0xFFFFFF00);
				paint.setStyle(Paint.Style.STROKE);
				paint.setStrokeJoin(Paint.Join.ROUND);
				paint.setStrokeCap(Paint.Cap.ROUND);
				paint.setStrokeWidth(3);
				
				canvas.drawPoint(event.getX(), event.getY(), paint);
				holder.unlockCanvasAndPost(canvas);
return true;
				
			}
    	});
    }
Member Avatar
woodenduck
Light Poster
29 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I would like to create a notebook type application that will accept touch input and allow you to draw on the surface view. I'm unsure what I'm doing wrong since I have not programmed for the Android before.

Here is what I have:

findViewById(R.id.pageSurface).setOnTouchListener(new View.OnTouchListener() {

			public boolean onTouch(View v, MotionEvent event) {
				SurfaceHolder holder = ((SurfaceView)findViewById(R.id.pageSurface)).getHolder();
				Canvas canvas = holder.lockCanvas();
				Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
				
				paint.setColor(Color.BLACK);
				paint.setDither(true); 
				paint.setColor(0xFFFFFF00);
				paint.setStyle(Paint.Style.STROKE);
				paint.setStrokeJoin(Paint.Join.ROUND);
				paint.setStrokeCap(Paint.Cap.ROUND);
				paint.setStrokeWidth(3);
				
				canvas.drawPoint(event.getX(), event.getY(), paint);
				holder.unlockCanvasAndPost(canvas);
return true;
				
			}
    	});
    }

This code actually will draw it turns out I cant have findViewById(R.id.pageSurface).setBackgroundColor(Color.WHITE); set outside of this method or it will cause the page to remain white...

Member Avatar
woodenduck
Light Poster
29 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I still need help to make the line solid. I get a dotted line that is spaced apart based on how fast I move my finger. Is there a way to continue drawing and updating dots while my finger is down?

Question Self-Answered as of 2 Years Ago
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: