Will it not just move the element as I move my finger on the screen. I want to draw the element at all positions where my finger has touched so that I can see a continuous drawing.
Let me know if I have misunderstood. On Sep 19, 3:03 am, Dianne Hackborn <hack...@android.com> wrote: > You don't need the history to do smooth tracking. The history gives you all > of the points between this in the last motion event... but when tracking > you always want to show your object at the most recent reported position, so > the history is irrelevant. > > The problem with the code is that it is trying to draw in to mCanvas > directly. The view hierarchy is update-based; you need to update the state > and then invalidate the view drawing it to show the new state. Even if you > could draw to the Canvas outside of an update, the code here would be broken > because it would just leave a trail of bitmaps drawn at various positions > without erasing the previous one. (Though I guess it is doing an > invalidate() after drawing the bitmap, so you'd end up with the bitmap being > briefly drawn and then erased as the invalidate is executed.) > > Anyway, just store the new position of the bitmap, call invalidate(), and > then in your onDraw() draw the bitmap at the current position. > > > > On Sun, Sep 18, 2011 at 7:20 AM, blake <blake.me...@gmail.com> wrote: > > If you look at the sample code in the Google documents you'll see that > > motion events have history. You'll need to use it to get a smooth > > trace > > -Blake > > Programming Android, FTW > > > On Sep 18, 5:20 am, "loril...@gmail.com" <loril...@gmail.com> wrote: > > > 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+unsubscr...@googlegroups.com > > For more options, visit this group at > >http://groups.google.com/group/android-developers?hl=en > > -- > Dianne Hackborn > Android framework engineer > hack...@android.com > > Note: please don't send private questions to me, as I don't have time to > provide private support, and so won't reply to such e-mails. All such > questions should be posted on public forums, where I and others can see and > answer them. -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en