The layout I'm currently using consists of a TabLayout with Viewpager2, what I'm trying to achieve is implementing another ViewPager2 to display several images in one of the tabs. But the issue I'm facing is when I swipe, I am only able to switch between tabs instead of switching images. Any help would be greatly appreciated, thanks!
Asked
Active
Viewed 121 times
0
-
[This link will help you](https://www.journaldev.com/19336/android-nested-viewpager-vertical-viewpager) – dennisrufigill Jul 29 '20 at 09:39
1 Answers
1
Found the solution, just add this piece of code into your program.
private void reduceDragSensitivity() {
try {
Field ff = ViewPager2.class.getDeclaredField("mRecyclerView") ;
ff.setAccessible(true);
RecyclerView recyclerView = (RecyclerView) ff.get(viewPager);
Field touchSlopField = RecyclerView.class.getDeclaredField("mTouchSlop") ;
touchSlopField.setAccessible(true);
int touchSlop = (int) touchSlopField.get(recyclerView);
touchSlopField.set(recyclerView,touchSlop*4);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
Remember to replace the viewPager with your own name, if you wish to read more about it: https://medium.com/@al.e.shevelev/how-to-reduce-scroll-sensitivity-of-viewpager2-widget-87797ad02414

Noxagon
- 15
- 6
-
i added this to top viewpager and to inner. does not work for me. – Evgeny GooDi Oct 28 '20 at 16:00