Here is a little more accurate than just getX and getY: historical touch events. I am sure this works with SDK8, but did not test it on lower versions.
@Override public boolean onTouchEvent(MotionEvent event) { int action = event.getAction(); mCurDown = action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE; int N = event.getHistorySize(); for (int i=0; i<N; i++) { drawPoint(event.getHistoricalX(i), event.getHistoricalY(i), event.getHistoricalPressure(i), event.getHistoricalSize(i)); } drawPoint(event.getX(), event.getY(), event.getPressure(), event.getSize()); return true; } private void drawPoint(float x, float y, float pressure, float size) { mCurX = (int)x; mCurY = (int)y; mCurPressure = pressure; mCurSize = size; mCurWidth = (int)(mCurSize*(getWidth()/3)); if (mCurWidth < 1) mCurWidth = 1; if (mCurDown && mBitmap != null) { int pressureLevel = (int)(mCurPressure*255); mPaint.setARGB(pressureLevel, 255, 255, 255); mCanvas.drawCircle(mCurX, mCurY, mCurWidth, mPaint); mRect.set(mCurX-mCurWidth-2, mCurY-mCurWidth-2, mCurX+mCurWidth+2, mCurY+mCurWidth+2); invalidate(mRect); } }
source share