Different fling (swipe) velocity on different Android devices with same density

后端 未结 3 1402
情话喂你
情话喂你 2021-02-01 18:32

I\'m writing my own image viewer that enables users to swipe left\\right to see the next\\previous image. I want to animate the image change according to the fling velocity.

3条回答
  •  故里飘歌
    2021-02-01 19:00

    Don't use the velocity: it is not easy to use. A swipe to the right it is a + number, to the left it is a - number. You could these:

    event1.getRawY() 
    event2.getRawY()
    event1.getRawX() 
    event2.getRawX()
    

    to determine if the swipe was left or right:

    if the first event was more than the second, the person swiped to the left, but you can say if the last event was x less than the first event, then the person's swipe was far enough and react to it. You can do the opposite for a swipe was to a right. Also, the onFling doesn't recognize small taps and just touches, so you can get away without comparing the distance velocity or length at all.

提交回复
热议问题