嵌套的 Recyclerview 自行滚动 [英] Nested Recyclerview scrolls by itself

查看:20
本文介绍了嵌套的 Recyclerview 自行滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个父 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设置为0child view 2 rv.它上面的一切都有价值.但是,我不确定是否是这种情况,因为我仍在寻找导致它的原因.

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 的每一项都包含一个水平的 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向上滚动,使得当前水平的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.

有一个简单的解决方法.将此添加到您的 outer/parent RecyclerView:

There is an easy fix. Add this to your outer/parent RecyclerView:

android:descendantFocusability="blocksDescendants"

我在这些问题中找到了解决方案:

I've found the solution in this questions:

此外,我发现了另一种解决方案,其中也有效.在我们的例子中,垂直的 RecyclerView 包含在 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屋!

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