简体   繁体   中英

Conflict between recyclerview scroll and viewpager swipe

In my app I have a ViewPager that has four fragments. All the fragments are composed of RecyclerView which can be scrolled vertically. My problem is that when I try to navigate to other fragments and swipe left or right, the RecyclerView's scroll is detected first (mostly) and instead of going to other fragments the RecyclerView gets scrolled.

To be more clear, if I scroll the recyclerView, then suddenly swipe left or right, the viewpager never swipes.

What should I do?

When you scroll your RecyclerView vertically and cross a threshold to trigger scrolling, it consumes the TouchEvent . This means the default behavior is until you release your finger from the screen, the ViewPager will not be able to trigger a horizontal scroll. This is default behavior for how scrolling views interact with each other. You could attempt to override touch handling by extending RecyclerView and ViewPager or having a coordinating view that dispatches all TouchEvent s to both views. However, either of these approaches could present a number of issues.

If you were to look at the Play Store for reference, its touch handling works the same as what you are seeing here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM