2012-12-05 4 views
0

내 표면보기에 문제가 있습니다. 사실 내가 표면보기에 어떤 물건을 그릴 때 (onMoving) 그리기 (show)가 아니지만 표면보기에서 손가락을 놓으면 그림이 그려집니다. 그래서 어느 누구든지 그것을 풀 수 있습니다.안 드 로이드의 표면보기 캔버스에서 그리는 방법

내 코드는 ...............

public boolean onTouch(View view, MotionEvent motionEvent) { 
    if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){ 

     currentDrawingPath = new DrawingPath(); 
     currentDrawingPath.paint = currentPaint; 
     currentDrawingPath.path = new Path(); 
     currentBrush.mouseDown(currentDrawingPath.path, motionEvent.getX(), motionEvent.getY());  

    }else if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){ 

     currentBrush.mouseMove(currentDrawingPath.path, motionEvent.getX(), motionEvent.getY());  

    }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){ 
     currentBrush.mouseUp(currentDrawingPath.path, motionEvent.getX(), motionEvent.getY());    
     drawingSurface.addDrawingPath(currentDrawingPath); 


    } 

    return true; 
} 

답변

-1

이 코드

Ourview v; 
Bitmap ball; 
float x,y; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    v = new Ourview(this); 
    v.setOnTouchListener(this); 
    ball = BitmapFactory.decodeResource(getResources(), R.drawable.circle_green); 
    x = y = 0; 
    setContentView(v); 
} 


@Override 
protected void onPause() { 
    // TODO Auto-generated method stub 
    super.onPause(); 
    v.pause(); 
} 

@Override 
protected void onResume() { 
    // TODO Auto-generated method stub 
    super.onResume(); 
    v.resume(); 
} 

public class Ourview extends SurfaceView implements Runnable{ 

    Thread t = null; 
    SurfaceHolder holder; 
    boolean isItOk = false; 

    public Ourview(Context context) { 
     super(context); 
     // TODO Auto-generated constructor stub 
     holder = getHolder(); 
    } 

    public void run() { 
     // TODO Auto-generated method stub 
     while (isItOk == true){ 
      //perfom convas drawing 
      if (!holder.getSurface().isValid()){ 
       continue; 
      } 
      Canvas c = holder.lockCanvas(); 
      c.drawARGB(250, 10, 50, 100); 
      c.drawBitmap(ball, x - (ball.getWidth()/2), y - (ball.getHeight()/2), null); 
      holder.unlockCanvasAndPost(c); 
     } 

    } 

    public void pause(){ 
     isItOk = false; 
     while(true){ 
      try{ 
       t.join(); 
      }catch (InterruptedException e){ 
       e.printStackTrace(); 
      } 
      break; 
     } 
     t = null; 

    } 

    public void resume(){ 
     isItOk = true; 
     t = new Thread(this); 
     t.start(); 

    } 

} 

public boolean onTouch(View v, MotionEvent me) { 
    // TODO Auto-generated method stub 

    try { 
     Thread.sleep(50); 
    } catch (InterruptedException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    switch(me.getAction()){ 
    case MotionEvent.ACTION_DOWN: 
     x = me.getX(); 
     y = me.getY(); 
     break; 
    case MotionEvent.ACTION_UP: 
     x = me.getX(); 
     y = me.getY(); 
     break; 
    case MotionEvent.ACTION_MOVE: 
     x = me.getX(); 
     //y = me.getY(); 
     break; 
    } 

    return true; 
} 

}

+0

감사를 시도하지만 완벽하게 작동하지 않습니다, 너는 그것을 시도했다. –

관련 문제