3

How to disable swipes left-to-right in new ViewPager2?
In ViewPager I can simple make CustomViewPager, but ViewPager2 is final class, so I can't extend it.

There was solution for two fragments, just disable user input after first swipe:

viewPager2.setUserInputEnabled(false)  

There was solution to return previous fragment, if catched left-to-right swipe, but it looks horrible (especially animation), when I need simple input disabling if deltaX < 0 .

Catching onPageScrolled with position and positionOffset has same horrible animations, and it can't catch very low values if user scroll even in medium speed.

I need migrate back to ViewPager?

  • I don't think there is a solution for that, you can take a look at https://stackoverflow.com/questions/9650265/how-do-disable-paging-by-swiping-with-finger-in-viewpager-but-still-be-able-to-s. for custom ViewPager – Bita Mirshafiee Nov 02 '20 at 05:22
  • But I think a better solution is to create several fragments and use right-to-left swiping to show your desired fragment. trying to making ViewPager custom as I think for this case is impossible or if it could be implemented should be so messy. – Bita Mirshafiee Nov 02 '20 at 05:24
  • @BitaMirshafiee thanks for the answer:) – Mikhail Kiselyov Nov 02 '20 at 19:35

0 Answers0