Need help with drawing on surface view in for android
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;
}
});
}
woodenduck
Newbie Poster
23 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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...
woodenduck
Newbie Poster
23 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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?
woodenduck
Newbie Poster
23 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Self-Answered as of 1 Year Ago