嵌套的Recyclerview本身会滚动 [英] Nested Recyclerview scrolls by itself
问题描述
我有一个父recyclerview,其中有3个子视图.孩子的最后两个是recyclerview.
I have a parent recyclerview that has 3 child view in it. The last two of the child are recyclerview.
Parent recyclerview
- child view 1
- child view 2 (horizontal rv)
- child view 3 (horizontal rv)
问题是,每当此片段可见时,它都会滚动自身以与child view 2
的底部对齐.
The issue is every time this fragment is visible, it scrolls itself to align with child view 2
's bottom.
我已将父rv设置为侦听滚动.这就是我最终得到的:
I have set the parent rv to listen for scroll. This is what I end up with:
dy: 108
dy: 72
dy: 75
dy: 62
dy: 48
dy: 42
dy: 34
dy: 27
dy: 22
dy: 16
dy: 12
dy: 10
dy: 7
dy: 5
dy: 3
dy: 3
dy: 1
dy: 1
dy: 1
似乎父recyclerview的起始dy
设置为child view 2
rv的0
.其上方的所有内容均具有-ve值.但是,我不确定是否是这种情况,因为我仍在寻找导致问题的原因.
It seems like the starting dy
of parent recyclerview is set to 0
to the child view 2
rv. Everything above it is in -ve value. However, I'm not sure if this was the case as I'm still finding out what causes it.
任何解决方法?
推荐答案
我们有一个类似的问题.我们有一个垂直的RecyclerView
.垂直RecyclerView
,就像在Android TV应用中一样.
We have a similar problem. We have a vertical RecyclerView
. Each item of this vertical RecyclerView
contains an horizontal RecyclerView
, like in the Android TV app.
当我们将支持库从23.4.0升级到24.0.0时,突然出现了自动滚动.特别是,当我们打开Activity
然后返回时,垂直RecyclerView
行不会被剪切,并且该行会完全显示.
When we upgraded the support libs from 23.4.0 to 24.0.0 the automatic scroll suddenly appeared. In particular, when we open an Activity
and we then go back, the vertical RecyclerView
scrolls up so that the current horizontal RecyclerView
row does not get cut and the row is displayed completely.
有一个简单的解决方法.将此添加到您的外部/父母 RecyclerView
:
There is an easy fix. Add this to your outer/parent RecyclerView
:
android:descendantFocusability="blocksDescendants"
我在以下问题中找到了解决方案:
I've found the solution in this questions:
- nested scrollview + recyclerview, strange autoscroll behaviour
- Android prevent nested recyclerview from automatically repositioning
此外,我找到了另一种解决方案,也可以.在我们的情况下,垂直FrameLayout
内部.如果将android:focusableInTouchMode="true"
添加到此FrameLayout
,问题就消失了.
Additionally, I've found another solution, which also works. In our case the vertical RecyclerView
is contained inside a FrameLayout
. If I add android:focusableInTouchMode="true"
to this FrameLayout
, the problem goes away.
顺便说一下,AOSP上还有一个公开问题.
By the way, there is also an open issue on the AOSP.
这篇关于嵌套的Recyclerview本身会滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!