Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

android - Nested Recyclerview scrolls by itself

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)

The issue is every time this fragment is visible, it scrolls itself to align with child view 2's bottom.

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

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.

Any fix?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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.

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

android:descendantFocusability="blocksDescendants"

I've found the solution in this questions:

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.

By the way, there is also an open issue on the AOSP.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...