FingerPaint API 데모 예제를 기반으로 화면에 그리기위한 간단한 안드로이드 응용 프로그램을 작성하고 있습니다. 데모에서는 손가락이 TOUCH_TOLERANCE가 정의한 화면에서 특정 거리를 이동 한 후에 만 그림이 시작됩니다. 손가락을 움직이지 않아도 점을 찍고 싶습니다. 가능한가?android.graphics.Path를 사용하여 도트를 그릴 수 있습니까?
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(0xFFAAAAAA);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}
private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;
private void touch_start(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);
//mPath.lineTo(x + 1, y + 1); //quick fix
mX = x;
mY = y;
}
private void touch_move(float x, float y) {
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;
}
}
private void touch_up() {
mPath.lineTo(mX, mY);
// commit the path to our offscreen
mCanvas.drawPath(mPath, mPaint);
// kill this so we don't double draw
mPath.reset();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touch_move(x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
touch_up();
invalidate();
break;
}
return true;
}
질문에 대한 답변 : http://stackoverflow.com/questions/17251416/android-fingerpaint-sample-does-not-draw-dot –