안드로이드 개발 질문/답변
(글 수 45,052)
@Override
public void onDraw(Canvas canvas) {
// canvas.drawColor(0xFFAAAAAA);
canvas.drawBitmap(currentBitmap, 0, 0, null);
canvas.drawBitmap(newBitmap, 0, 0, mBitmapPaint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX(); // 현재 좌표
float y = event.getY(); // 현재 좌표
if (event.getAction() == MotionEvent.ACTION_DOWN) // 터치 다운이면 이벤트 계속 받게
{
touch_start(x, y);
invalidate();
return true;
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
touch_move(x, y);
invalidate();
return true;
} else if (event.getAction() == MotionEvent.ACTION_UP) {
touch_up(x, y);
invalidate();
return true;
}
return super.onTouchEvent(event);
}
private void touch_up(float x, float y) {
// TODO Auto-generated method stub
mPath.lineTo(mX, mY);
Log.i("lineTo", mX + ":" + mY);
// commit the path to our offscreen
mCanvas.drawPath(mPath, mPaint);
// kill this so we don't double draw
mPath.reset();
}
private void touch_move(float x, float y) {
// TODO Auto-generated method stub
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
// if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
mX = x;
mY = y;
mCanvas.drawPath(mPath, mPaint);
// }
}
private void touch_start(float x, float y) {
// TODO Auto-generated method stub
mPath.reset();
mPath.moveTo(x, y);
mX = x;
mY = y;
}
터치무브시 페인트가 연결되서 잘아옴니다 하지만 터치 다운한다음 바로 업을 했을때 찍히도록 하는 방법은 없을까요??