开发者

what is the purpose of gesture in android?

what is the purpose of gesture in android??? touchscreen mobile in android how they implement sliding .when finger just touch th开发者_高级运维e screen how the images are scrolled ?? anybody can explain pls


I'm not sure what you mean, but the purpose is to use custom gestures and map them to actions. For example, you can map the 'O' gesture with the action of reloading.

And about the second question, if you mean how to scroll when gestures are enabled... Well you can specify whether the the custom gesture capture should override other touch events (for example the scrolling) with the property android:eventsInterceptionEnabled="true" within the tag <android.gesture.GestureOverlayView>.

You should really have a look to the official documentation's tutorial about it, if you haven't done it yet.

Regards.


If you want to slide a menu up and down and have it overshoot like the contacts application does, then do this:

  • When a touch first occurs, record the Y position
  • As they drag around, scroll the target using the difference between last Y position and the current one
  • When the touch is released, use the last recorded difference as your velocity
  • Scroll the target on every frame iteration using the velocity
  • Decrease the velocity by using a friction multipler
  • Stop scrolling when the next touch occurs (or when the velocity reaches 0)

Some pseudo-pseudo code...

lastTouchY = 0.0
friction = 0.98
touching = false
target = Object()
velocity = 0.0

onTouchDown(data)
   touching = true
   lastTouchY = data.y
   velocity = 0

onTouchMove(data)
   target.y += data.y - lastTouchY
   lastTouchY = data.y

onTouchUp(data)
   velocity = data.y - lastTouchY
   touching = false

onUpdate()
   if !touching
      target.y += velocity
      velocity *= friction
   if velocity < 1.0 - friction
      velocity = 0 // Stop updating when velocity is too low
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜