Sunday, September 18, 2011

[android-developers] onTouchEvent not called on every touch motion

I want to let a user smoothly draw elements with his finger and avoid
any lags as follows:

public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mCanvas.drawBitmap(primitive, x, y, mPaint);

invalidate();
break;
case MotionEvent.ACTION_MOVE:
mCanvas.drawBitmap(primitive, x, y, mPaint);

invalidate();
break;
case MotionEvent.ACTION_UP:
mCanvas.drawBitmap(primitive, x, y, mPaint);

invalidate();
break;
}
return true;
}
}

Using android SDK I find onTouchEvent is not called for every motion
event. This results in drawing of a bitmap only at the points when the
motion event is detected.

I can do this very easily using iPhone SDK . Can anyone confirm if
this is a limitation in Android or if there is a way we can increase
the rate of motion events?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate