1. Check out our app, Forums for Android! Download and leave feedback here!

Draw on canvas (SurfaceView)

Discussion in 'Application Development' started by hollowback, Dec 28, 2009.

  1. hollowback

    hollowback Member
    Thread Starter
    5

    Nov 12, 2009
    5
    0
    5
    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 (Text):
    1. _canvas = holder.lockCanvas();
    2.         if (event.getAction() == MotionEvent.ACTION_DOWN) {
    3.             _path = new Path();
    4.             _path.moveTo(event.getX(), event.getY());
    5.             _path.lineTo(event.getX(), event.getY());
    6.         } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
    7.             _path.lineTo(event.getX(), event.getY());          
    8.             _canvas.drawPath(_path, mPaint);
    9.             _path = new Path();
    10.             _path.moveTo(event.getX(), event.getY());
    11.         } else if (event.getAction() == MotionEvent.ACTION_UP) {
    12.             _path.lineTo(event.getX(), event.getY());
    13.             _canvas.drawPath(_path, mPaint);
    14.         }      
    15.         holder.unlockCanvasAndPost(_canvas);
    16.  
    But when I draw, it shows something like that:
    [​IMG]
    so I draw another lines and image changes to
    [​IMG]

    In constructor of my MySurface class (which extends SurfaceView and implements SurfaceHolder.Callback) i set up holder variable:
    Code (Text):
    1.         holder = getHolder();
    2.         holder.addCallback(this);
    Does anybody know what is wrong?
     

    Advertisement

  2. Macrex

    Macrex New Member
    5

    Apr 4, 2012
    1
    0
    5
    man, I'm having the same problem.
    you managed to solve?

    thank you
     
  3. jonbonazza

    jonbonazza Well-Known Member
    163

    Jul 13, 2010
    1,934
    458
    163
    Male
    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.
     

Share This Page

Loading...