Recyclerview inside ScrollView not scrolling smoothly
Solution 1
Try doing:
RecyclerView v = (RecyclerView) findViewById(...);
v.setNestedScrollingEnabled(false);
As an alternative, you can modify your layout using the support design library. I guess your current layout is something like:
<ScrollView >
<LinearLayout >
<View > <!-- upper content -->
<RecyclerView > <!-- with custom layoutmanager -->
</LinearLayout >
</ScrollView >
You can modify that to:
<CoordinatorLayout >
<AppBarLayout >
<CollapsingToolbarLayout >
<!-- with your content, and layout_scrollFlags="scroll" -->
</CollapsingToolbarLayout >
</AppBarLayout >
<RecyclerView > <!-- with standard layoutManager -->
</CoordinatorLayout >
However this is a longer road to take, and if you are OK with the custom linear layout manager, then just disable nested scrolling on the recycler view.
Edit (4/3/2016)
The v 23.2
release of the support libraries now includes a factory “wrap content” feature in all default LayoutManager
s. I didn’t test it, but you should probably prefer it to that library you were using.
<ScrollView >
<LinearLayout >
<View > <!-- upper content -->
<RecyclerView > <!-- with wrap_content -->
</LinearLayout >
</ScrollView >
Solution 2
I only needed to use this:
mMyRecyclerView.setNestedScrollingEnabled(false);
in my onCreateView()
method.
Thanks a lot!
Solution 3
You can use this way either :
Add this line to your recyclerView xml file :
android:nestedScrollingEnabled="false"
Or in java code :
RecyclerView.setNestedScrollingEnabled(false);
Hope this helped .
Solution 4
You can try with both the ways with XML and programmatically. But the issue you may face is (below API 21) by doing it with XML will not work . So it's better to set it programmatically in your Activity / Fragment.
XML code:
<android.support.v7.widget.RecyclerView
android:id="@+id/recycleView"
android:layout_width="match_parent"
android:visibility="gone"
android:nestedScrollingEnabled="false"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayoutBottomText" />
Programmatically:
recycleView = (RecyclerView) findViewById(R.id.recycleView);
recycleView.setNestedScrollingEnabled(false);
Solution 5
Using Nested Scroll View instead of Scroll View solved my problem
<LinearLayout> <!--Main Layout -->
<android.support.v4.widget.NestedScrollView>
<LinearLayout > <!--Nested Scoll View enclosing Layout -->`
<View > <!-- upper content -->
<RecyclerView >
</LinearLayout >
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
Related videos on Youtube
Bart Bergmans
Updated on July 10, 2021Comments
-
Bart Bergmans almost 3 years
For my app I am using a
RecyclerView
inside aScrollView
where theRecyclerView
has a height based on its content using this library. Scrolling is working but it's not working smoothly when I scroll over theRecyclerView
. When I scroll over theScrollView
itself it is scrolling smoothly.The code I am using to define the
RecyclerView
:LinearLayoutManager friendsLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext(), android.support.v7.widget.LinearLayoutManager.VERTICAL, false); mFriendsListView.setLayoutManager(friendsLayoutManager); mFriendsListView.addItemDecoration(new DividerItemDecoration(getActivity().getApplicationContext(), null));
The
RecyclerView
in theScrollView
:<android.support.v7.widget.RecyclerView android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:id="@+id/friendsList" android:layout_width="match_parent" android:layout_height="wrap_content" />
-
Houssin Boulla about 7 yearsthis solution work for me: stackoverflow.com/a/32390370/7308789 thank you
-
Pravin Divraniya almost 5 years@tahaDev what exactly not working in your case please elaborate more on that. Also, it seems like no provided solutions worked in your case, is it so?
-
Saswata almost 5 yearsUse
androidx.constraintlayout.widget.ConstraintLayout
which will solve your problem without any complex implementations
-
-
Richard Le Mesurier about 8 yearsTo add to this answer:
setNestedScrollingEnabled(false)
only worked when I switched out theScrollView
for aNestedScrollView
instead. -
Micro about 8 yearsFor me,
setNestedScrollingEnabled(false)
gave me back smooth scrolling with myRecyclerView
inside of aScrollView
- Thanks! But I still don't understand why that works...? What does it really mean to set nested scrolling false? -
Eric B. almost 8 yearsNote that
android:nestedScrollingEnabled="false"
only works for API 21+ butv.setNestedScrollingEnabled(false)
is OK for <21. -
drod almost 8 yearsThis seems to work fine and saved me hours of work. Thanks. Is there any downside to using this solution? Because there are a lot of comments out there stating this is not a good solution, that you should not put scrolling views inside one another.
-
natario almost 8 years@drod these comments are probably very old. Since nested scrolling was introduced, it is ok to nest scrolling views.
-
Hossain Khan over 7 yearsFor future reference, if anybody is experiencing
RecyclerView
wrap_content issue insideScrollView
that only happens on marshmallow/nougat (API 23, 24) devices, check my workaround at stackoverflow.com/a/38995399/132121 -
EngineSense over 7 years@MicroR another problem pops up, nested view content will be scrolled out by recyclerview every time
-
Muhammad Riyaz over 7 yearsrequires Api 21+
-
Daniel W. about 7 yearsA downside to this solution I'm experiencing right now is that the RecyclerView will not receive events in it's onScrollListener. Which I need because I want to fetch more data when I have only a certain amount of items in the recycler
-
natario about 7 years@Daniel if the recycler is wrap_content, it means it can't scroll. Maybe use a special item, like a progress bar, and fetch data onBindViewHolder of that particular item.
-
ken about 7 years
setNestedScrollingEnabled(false)
just make the recycleview fast..still dont know what happen..haha -
priyanka about 7 yearsv.setNestedScrollingEnabled(false); This line helped a lot..Thanks
-
Justcurious about 7 yearssetNestedScrollingEnabled(false) Solved my issue of scroll
-
Sreeram Sunkara over 6 yearsThis solution solved the scroll effect, I have continuation problem from this. I want to have drag option for the RecyclerView. I can only drop the item in the visible items on the screen. Not able to drop it on the items that are not visible in the list. I can achieve it if I remove NestedScrollView. I tried requestDisallowInterceptTouchEvent in onTouchEvent but no luck. Anyone had the same problem?
-
brijexecon over 6 yearsJust added nestedScrollingEnabled="false" in recyclerview It worked for me. Thanks for ur support.
-
Gökberk Yağcı over 3 yearsIt is working for me too. But i do not understand how it exactly solve this issue ? What is the solution behind it ?