Android: How to handle right to left swipe gestures

前端 未结 22 1196
日久生厌
日久生厌 2020-11-21 06:18

I want my app to recognize when a user swipes from right to left on the phone screen.

How to do this?

22条回答
  •  时光说笑
    2020-11-21 07:05

    This question was asked many years ago. Now, there is a better solution: SmartSwipe: https://github.com/luckybilly/SmartSwipe

    code looks like this:

    SmartSwipe.wrap(contentView)
            .addConsumer(new StayConsumer()) //contentView stay while swiping with StayConsumer
            .enableAllDirections() //enable directions as needed
            .addListener(new SimpleSwipeListener() {
                @Override
                public void onSwipeOpened(SmartSwipeWrapper wrapper, SwipeConsumer consumer, int direction) {
                    //direction: 
                    //  1: left
                    //  2: right
                    //  4: top
                    //  8: bottom
                }
            })
    ;
    

提交回复
热议问题