SimpleOnGestureListener.OnScroll does not work correctly on fast scrolling

I need to change the image when the user clicks from left to right; why i used SimpleOnGestureListener

to detect swipe event on ImageView

.

In this process, when I scroll the image slowly, the method onScroll()

calls frequently and everything works fine, but when I scroll that image quickly, the method onScroll()

is called almost two or three times, please let me know what I have to use for the method to be onScroll()

called according to the speed of the swipe.

+3


source to share


2 answers


I can think of other ways to achieve what I want



onFling()

gives speed X

and Y

: if it is more than 4000, it is considered fast scrolling, then you can animate continuous image, its effect is like fast scrolling.

+1


source


As much as there is a lot of detail, I am leaving my answer here, not adding comments.

onFling

gives four useful parameters: two MotionEvent

and two speed numbers. With this useful information you can call fling

on Scroller

. The scroller object will do the rest for you (for example, get the current x / y value after a while).

In your case, you can call computeScrollOffset

and getCurrX/getCurrY

handle your "swipe animation". Just change the displayed image when the x / y view reaches the border.



For example, suppose your pointer position is (0,0) and the initial x velocity is 1000 pixels / second. After 500 milliseconds, you call computeScrollOffset

(it will surely return true), or it getCurrX

might return 600 (since fling doesn't go linear). The exact time to change the image is up to you.

There Scroller

should be many examples for detailed use . One good example is definitely the official curriculum reduction

+3


source







All Articles