1. Are you ready for the Galaxy S20? Here is everything we know so far!

Draw on canvas (SurfaceView)

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

  1. hollowback

    hollowback Lurker
    Thread Starter

    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?
     


  2. Macrex

    Macrex Lurker

    man, I'm having the same problem.
    you managed to solve?

    thank you
     
  3. jonbonazza

    jonbonazza Android Expert

    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.
     
Loading...
Similar Threads - Draw canvas SurfaceView
  1. Rad Brothers
    Replies:
    1
    Views:
    658
  2. App Update
    Replies:
    0
    Views:
    101
  3. App Update
    Replies:
    0
    Views:
    95
  4. The_Chief
    Replies:
    7
    Views:
    983
  5. Muffi Zainu
    Replies:
    18
    Views:
    4,979
  6. Phrozt
    Replies:
    1
    Views:
    263
  7. Kevin Barnes
    Replies:
    1
    Views:
    218
  8. ClintonBrits
    Replies:
    0
    Views:
    370
  9. Valera_1987_01
    Replies:
    1
    Views:
    495
  10. Zaheer Ahmed
    Replies:
    0
    Views:
    1,223

Share This Page

Loading...