How to use a ViewPager2 inside another ViewPager2(如何在另一个 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在另一个 ViewPager2 中使用 ViewPager2
基础教程推荐
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
