I have spend two days browsing the web for how to animate a view once a fling gesture has been detected on a view. I have read SO questions like this. I can animate the view with a fragment transaction or by animating it to where the user has dragged the view to in the MotionEvent.ACTION_MOVE, and when ACTION_UP then use scrollTo() method to scroll the view off the screen. But none of these solutions makes a smooth "fling" or "slide". How can I do this? I have tried using Scroller and OverScroller without any luck.
Asked
Active
Viewed 449 times
0
-
use [FlingAnimation](https://developer.android.com/reference/android/support/animation/FlingAnimation.html) – pskink Jun 15 '17 at 05:08
-
Cannot get it to resolve symbol. I have added the dependency for it. – Kæmpe Klunker Jun 15 '17 at 05:21
-
what dependency? – pskink Jun 15 '17 at 05:29
-
You need to add this dependency compile "com.android.support:support-dynamic-animation:26.0.0-beta2" according to https://developer.android.com/topic/libraries/support-library/preview/physics-based-animation.html – Kæmpe Klunker Jun 15 '17 at 09:18
-
yes, but 25.4 is enough – pskink Jun 15 '17 at 09:22
-
Still after adding it, it cannot resolve FlingAnimation, but DynamicAnimation it can. – Kæmpe Klunker Jun 15 '17 at 09:33
-
just used 26.0.0-beta1 with no problems – pskink Jun 15 '17 at 09:41
-
Like this? FlingAnimation fling = new FlingAnimation(view, DynamicAnimation.SCROLL_X); – Kæmpe Klunker Jun 15 '17 at 11:00
-
yes, just like this – pskink Jun 15 '17 at 11:06
-
Okay it can resolve SpringAnimation. This is just epic troll.... – Kæmpe Klunker Jun 15 '17 at 11:17
-
[here](https://developer.android.com/topic/libraries/support-library/preview/fling-animation.html) you have `FlingAnimation` related samples, just follow them – pskink Jun 15 '17 at 12:39
-
That is the code I'm trying to implement. Do you need anything else than this dependency? Can I only create the FlingAnimation inside an onFling method or something crazy? – Kæmpe Klunker Jun 15 '17 at 12:51
-
Don't know what to do then. Impossible to solve it.. – Kæmpe Klunker Jun 15 '17 at 19:25
-
It is actually not. Any idea why it isn't? – Kæmpe Klunker Jun 16 '17 at 09:50