Android viewpager detect swipe beyond the bounds

后端 未结 4 781
自闭症患者
自闭症患者 2021-01-20 23:40

In my Android application, I am using a viewpager for image swiping. My requirement is, if a user swipes out of the first and last page, the activity should finish.

I ha

4条回答
  •  别那么骄傲
    2021-01-21 00:31

    I have also used the code from this SO answer. Make sure you make the necessary changes to your activity class. Here's what I did...

    I changed my activity so it implements CustomViewPager.OnSwipeOutListener.

    In my activity, after my mPager = (CustomViewPager) findViewById(R.id.pager); line, I call mPager.setOnSwipeOutListener(this);

    All you need to do then is override the onSwipeOutAtStart() and onSwipeOutAtEnd() methods in your activity.

提交回复
热议问题