Android: Swipe left to right and right to left

牧云@^-^@ 提交于 2019-12-04 23:14:35
Samuel

Comment out the

iv.setOnClickListener

in your activity and I think the fling should be working.

Mojo1

Sorry I am not super knowledgable and am actually trying to work on this question myself... I am using titanium api in order to program so I am not familiar with the syntax of your code, though I get the general idea... (Still on a 2 week training period for my internship)

TO THE POINT THOUGH, I see the following lines of code pretty early on

//right to left swipe
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
    isRightToLeft = true;
    return true;
}               
// left to right swipe
else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
    isRightToLeft = false;
    return true;
}

It looks like your equation

if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX)

will work to detect a swipe... However the ABS() function in your code will cause you to only interpret the magnitude of the swipe, and will be unable to tell a difference in direction. Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!