📃RecyclerView SmoothScrollToPosition Not Working within NestedScrollView Solution— Android.✔
Scroll your recycler view within a Nested scroll view easily
This Story belongs to what I have learned today. As you can see from the article title that recyclerView smoothScrollToPosition() not working within NestedScrollView, now how the layout file looks like and what I mean to say that all the confusion will be clear so you can see the XML file from the below Snippet.
Visit my website at https://danishamjad.com/
I had a case that I have a screen with a top static section and then I have a recycler view in which I need to show the comments list. And I need to scroll the whole screen that’s why I used NestedScrollView.
When the user sends a comment it will be displayed on the top of the List means on 0 positions, so in my case, I need to scroll the List to 0 positions whenever user comments.
The screen which I used is like the below image.
After so many efforts I came to the solution, that recyclerView scroll not working whenever we add within the nested scroll view. That is why
smoothScrollToPosition() not working.
Now, without wasting the time let’s jump to the solution 🛫
The solution is to use
nestedscroll.smoothScrollTo(0,0) here you need to use the nested scroll Id.
Now, this will let you move towards the top of the screen, but in my case, I need to scroll from where I started the recycler view, so for that, you need to use the view height and need to define in your Y position like below:
This article described you to how RecyclerView SmoothScrollToPosition working within NestedScrollView.
I hope this article is helpful. If you think something is missing, have questions, or would like to give feedback, go ahead and leave a comment below. I’d appreciate the feedback.
I’ve written some other Android-related content, and if you liked what you read here, you’ll probably also enjoy this: