如何在另一个ViewPager2中使用ViewPager2 [英] How to use a ViewPager2 inside another ViewPager2

查看:98
本文介绍了如何在另一个ViewPager2中使用ViewPager2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在另一个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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆