我在另一个 ViewPager2 中使用 ViewPager2.因此,幻灯片仅适用于根 ViewPager.如何让两个 ViewPager 都工作?
I use a ViewPager2 inside another ViewPager2. Because of this, the slide only works for the root ViewPager. How to make both ViewPager work?
正如文档所说:
"支持嵌套滚动元素
"Support nested scrollable elements
在滚动视图与包含它的 ViewPager2 对象具有相同方向的情况下,ViewPager2 本身不支持嵌套滚动视图.例如,滚动不适用于垂直方向的 ViewPager2 对象内的垂直滚动视图.
ViewPager2 does not natively support nested scroll views in cases where the scroll view has the same orientation as the ViewPager2 object that contains it. For example, scrolling would not work for a vertical scroll view inside a vertically-oriented ViewPager2 object.
要支持 ViewPager2 对象内具有相同方向的滚动视图,当您希望滚动嵌套元素时,必须在 ViewPager2 对象上调用 requestDisallowInterceptTouchEvent().ViewPager2 嵌套滚动示例演示了一种使用通用自定义包装布局解决此问题的方法."
To support a scroll view inside a ViewPager2 object with the same orientation, you must call requestDisallowInterceptTouchEvent() on the ViewPager2 object when you expect to scroll the nested element instead. The ViewPager2 nested scrolling sample demonstrates one way of solving this problem with a versatile custom wrapper layout."
我自己试过了,效果很好,你需要使用这个类.
I have tried it myself and it works just fine, you need to use this class.
这是文档的链接.
这篇关于如何在另一个 ViewPager2 中使用 ViewPager2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!