How can I limit fling in Android gallery to just one item per fling?

前端 未结 6 1511
半阙折子戏
半阙折子戏 2020-11-30 03:43

I have a gallery with several full screen images. I want to limit the fling gesture to only advance one image at a time (like the HTC Gallery app). What\'s the right/easiest

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 04:06

    I have a solution, which, although it does not guarantee at most one advance, is extremely simple (and likely does what you would do manually in code): simply decrease the x-velocity in the onFling parameter. That is, override the onFling to simply look like this:

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        return super.onFling(e1, e2, velocityX / 4, velocityY);
    }
    

    Best,

    Michael

提交回复
热议问题