Search code examples
androidswipepull-to-refresh

Rotate view/object based on how far and fast I slide my finger across the screen (Android


Similar to pull-to-refresh functionality I want to rotate a view (maybe a small image) based on how far a slide my finger across the screen (anywhere on the screen)....once my finger leaves the screen I want the view to rotate in reverse back to its original state

To give some more information about my intended use of this functionality: I have an image and when the user swipes their finger across this image (right) for a certain distance and then releases the swipe I want to open a new activity The rotating object just provides some visual feedback for the users swipe gesture

I tried to implement this using Rotation Animation and had a very difficult time, I also cant find any answers any were on the web...if someone could help me it would be a life saver


Solution

  • You should use onTouchEvent method of Activity to listen for user gestures. Then in onTouchEvent use GestureDetector to be notified about gestures. You can use GestureDetector.OnGestureListener to be notified about onScroll event. Then rotate your view using ObjectAnimator class. This Android tutorial shows how to discover and utilize Scroll gesture. Animating a Scroll Gesture