Difference between onScroll() and onFling() of GestureDetector - android

What is the difference between onScroll() and onFling() in the GestureDetector interface?
When I print out the events they are showing the exact same things. At least the last onScroll() and the onFling().
The only true difference I noticed is that onScroll() is called much more often, fling always just one time.

The difference between Scroll and fling
onFling: is that the user lifts his finger in the end of the movement (that is the reason for what onFling is called one time).
onScroll: is the general process of moving the viewport (that is, the 'window' of content you're looking at).
Understand Scrolling Terminology "Scrolling" is a word that can take on different meanings in Android, depending on the context.
Scrolling is the general process of moving the viewport (that is, the
'window' of content you're looking at). When scrolling is in both the
x and y axes, it's called panning. The sample application provided
with this class, InteractiveChart, illustrates two different types of
scrolling, dragging and flinging:
Dragging is the type of scrolling that occurs when a user drags her
finger across the touch screen. Simple dragging is often implemented
by overriding onScroll() in GestureDetector.OnGestureListener. For
more discussion of dragging, see Dragging and Scaling.
Flinging is the type of scrolling that occurs when a user drags and lifts her finger
quickly. After the user lifts her finger, you generally want to keep
scrolling (moving the viewport), but decelerate until the viewport
stops moving. Flinging can be implemented by overriding onFling() in
GestureDetector.OnGestureListener, and by using a scroller object.

Related

What is the difference between Scroll and Fling in android.widget.Scoller

While I'm reading the source code of android.widget.Scoller, I found the property mMode probably has 2 available value which are SCROLL_MODE = 0; and FLING_MODE = 1; What are the differences between scroll and fling gesture? Can anyone help explain it?
"Scrolling" is a word that can take on different meanings in Android,
depending on the context.
Scrolling is the general process of moving the viewport (that is, the
'window' of content you're looking at). When scrolling is in both the
x and y axes, it's called panning. The sample application provided
with this class, InteractiveChart, illustrates two different types of
scrolling, dragging and flinging:
Dragging is the type of scrolling that occurs when a user drags her finger across the touch screen. Simple dragging is often
implemented by overriding onScroll() in GestureDetector.OnGestureListener. For more discussion of dragging,
see Dragging and Scaling.
Flinging is the type of scrolling that occurs when a user drags and lifts her finger quickly. After the user lifts her finger, you
generally want to keep scrolling (moving the viewport), but decelerate
until the viewport stops moving. Flinging can be implemented by
overriding onFling() in GestureDetector.OnGestureListener, and by
using a scroller object.

SimpleOnGestureListener.OnScroll isn't calling properly on fast scrolling

I need to change an image when the user swipes from left to right; that's why I have used SimpleOnGestureListener to detect a swipe event on an ImageView.
In this process, when I swipe an image slowly, the onScroll() method calls frequently and every thing is working fine but when I swipe this image fastly, the onScroll() method called hardly only two three times, please let me know what should I use to make the onScroll() method called according swipe's speed.
As there's much detail to say, I post my answer here rather than adding comments.
onFling gives you four useful parameters : two MotionEvent and two velocity numbers. With these useful information you can call fling on a Scroller. The scroller object will do the rest work for you (e.g. get current x/y value after some time).
For your case, you could call computeScrollOffset and getCurrX/getCurrY to deal with your "swipe animation". Just change your showing image when the View's x/y reaches the boundary.
For instance , suppose your pointer up position is (0,0) and initial x velocity is 1000 pix/second. After 500 milliseconds, you call computeScrollOffset (it will return true certainly) and getCurrX might return 600 (because fling doesn't go linearly).The exact time to change the image is up to you.
For detail usage of Scroller there should be a lots of examples out there. One good example is certainly the official training lession
I can think of other ways of achieving what you want
onFling() gives you the velocity of X and Y: if it's greater than 4000 it counts as a fast scroll, then you can animate the continuous image, its effect like fast swiping.

Android "swipe" vs "fling"

In the Android Developers gesture design section, the term "swipe" is used.
In the developer section, the term "fling" is used.
Are these terms synonymous? From what I have found, I believe they are, but nowhere is it explicitly said one way or the other.
That said, if I want to implement functionality for a "swipe," should I implement onFling in GestureDetector?
Drag, swipe, or fling details
Swipe gesture activities vary based on context. The speed at which a gesture is performed is the primary distinction between Drag, Swipe, and Fling.
Drag: Fine gesture, slower, more controlled, typically has an on-screen target
Swipe: Gross gesture, faster, typically has no on-screen target
Fling: Gross gesture, with no on-screen target
Gesture velocity impacts whether the action is immediately reversible.
A swipe becomes a fling based on ending velocity and whether the affected element has crossed a threshold (or point past which an action can be undone).
A drag maintains contact with an element, so reversing the direction of the gesture will drag the element back across the threshold.
A fling moves at a faster speed and removes contact with the element while it crosses the threshold, preventing the action from being undone.
from https://www.google.com/design/spec/patterns/gestures.html
onFling() will get executed when a user makes a "fling" motion, and said motion has a velocity with it to determine the type of fling it was. However, if a user simply touches the device and moves slowly across the screen, that would not be considered a fling, but a swipe.
It comes down to what type of motion you expect the users to perform. The ideal case would be to implement the onFling() function to capture that motion, and also implement onDrag() and onDragFinished() to capture the more subtle motions that should still be considered a swipe.

ViewPager (and its swiping) in the header of a ListView

I have a ViewPager inside a header of a ListView, and I noticed that, when you're swiping the viewpager, if the finger moves a little bit on the Y axis, the event gets canceled (I guess it's intercepted by the listview?).
The only way to swipe a picture, is to just slide your finger through few pixels, since there'll be less probabilities that you're moving your finger along the Y axis.
Is there a way to make the listview not to intercept the Y axis events in case they happened in the viewpager? I don't even know if this is what I need anyways.
Thanks a lot in advance.
You can try to intercept touch event
Take a look at this post Android - ViewPager scrolling resets
hope it helps
good luck

What is the purpose of "onFling" and "onScroll" event in GestureDetector of Android?

I am developing an Android application. I am novice in Touch enabled Android Application. I have read the article about onFling and onScroll events on:
http://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html
But I didn't get exactly what is the meaning and for what we can use onFling and onScroll events.
onScroll event is when user touches down the screen, moves finger in some direction and lift up. It is mostly used to scroll larger layouts over a smaller viewport. onFling is the same, but made faster and usually triggers an animation that keeps scrolling few moments more after finger lifted up.

Categories

Resources