How can I make work ViewPager with RecyclerView inside NestedScrollView(如何在 NestedScrollView 中使用 RecyclerView 制作 ViewPager)
问题描述
我正在使用带有 ViewPager 的 NestedScrollView.NestedScrollView 内部有一个 LinearLayout,最后有一些 TextView、TabLayout 和 ViewPager.TextViews 占据了大部分空间,而为 ViewPager 留下了一点空间.ViewPager 使用两个 Fragment,其中一个有几个 TextViews 和 ImageViews,另一个 Fragment 有一个 RecyclerView.
I am using NestedScrollView with ViewPager. NestedScrollView has a LinearLayout inside with some TextViews, TabLayout and ViewPager at the end. TextViews occupy most of the space and for ViewPager left a little space. ViewPager using two fragments, in one of them there is a few TextViews and ImageViews and in another fragment there is a RecyclerView.
当我将 ViewPager 的高度设置为 WRAP_CONTENT
时,它只占用剩下的空间,我无法滚动查看第一个片段的其余部分,而第二个片段在小 ViewPager 内滑动.
When I set ViewPager's height to WRAP_CONTENT
it takes only space that left and I can't scroll to see the rest of the first fragment, and the second fragment scoll inside little ViewPager.
例如,当我将 ViewPager 的高度设置为 1000dp 时,我可以在第一个片段上向下滚动,但第二个片段仍在小 ViewPager 内滚动.在我使用 RecyclerView scoll 在第一个 Fragment 中滚动片段后不再工作.
When I set ViewPager's height to 1000dp for example, I am able to scroll down on first fragment, but the second fragment still scrolling inside little ViewPager. And after I scroll in fragment with RecyclerView scoll in the first Fragment not working anymore.
如何解决滚动问题并使 ViewPager 与 WRAP_CONTENT
一起工作?
How can I fix scrolling problem and make ViewPager work with WRAP_CONTENT
?
这是我的代码:
推荐答案
我认为你应该像这样覆盖 ViewPager:
I think you should override ViewPager like this:
这篇关于如何在 NestedScrollView 中使用 RecyclerView 制作 ViewPager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!