1. Download our Official Android App: Forums for Android!

Apps Draw on canvas (SurfaceView)

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

  1. hollowback

    hollowback Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Nov 12, 2009

    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 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Apr 4, 2012

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

    thank you
     
  3. jonbonazza

    jonbonazza Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    1,930
    Joined:
    Jul 13, 2010

    Jul 13, 2010
    1,930
    457
    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...