Recyclerview inside ScrollView not scrolling smoothly

114,725

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 LayoutManagers. 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>
Share:
114,725

Related videos on Youtube

Bart Bergmans
Author by

Bart Bergmans

Updated on July 10, 2021

Comments

  • Bart Bergmans
    Bart Bergmans almost 3 years

    For my app I am using a RecyclerView inside a ScrollView where the RecyclerView has a height based on its content using this library. Scrolling is working but it's not working smoothly when I scroll over the RecyclerView. When I scroll over the ScrollView 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 the ScrollView:

    <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
      Houssin Boulla about 7 years
      this solution work for me: stackoverflow.com/a/32390370/7308789 thank you
    • Pravin Divraniya
      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
      Saswata almost 5 years
      Use androidx.constraintlayout.widget.ConstraintLayout which will solve your problem without any complex implementations
  • Richard Le Mesurier
    Richard Le Mesurier about 8 years
    To add to this answer: setNestedScrollingEnabled(false) only worked when I switched out the ScrollView for a NestedScrollView instead.
  • Micro
    Micro about 8 years
    For me, setNestedScrollingEnabled(false) gave me back smooth scrolling with my RecyclerView inside of a ScrollView - Thanks! But I still don't understand why that works...? What does it really mean to set nested scrolling false?
  • Eric B.
    Eric B. almost 8 years
    Note that android:nestedScrollingEnabled="false" only works for API 21+ but v.setNestedScrollingEnabled(false) is OK for <21.
  • drod
    drod almost 8 years
    This 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
    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
    Hossain Khan over 7 years
    For future reference, if anybody is experiencing RecyclerView wrap_content issue inside ScrollView that only happens on marshmallow/nougat (API 23, 24) devices, check my workaround at stackoverflow.com/a/38995399/132121
  • EngineSense
    EngineSense over 7 years
    @MicroR another problem pops up, nested view content will be scrolled out by recyclerview every time
  • Muhammad Riyaz
    Muhammad Riyaz over 7 years
    requires Api 21+
  • Daniel W.
    Daniel W. about 7 years
    A 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
    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
    ken about 7 years
    setNestedScrollingEnabled(false) just make the recycleview fast..still dont know what happen..haha
  • priyanka
    priyanka about 7 years
    v.setNestedScrollingEnabled(false); This line helped a lot..Thanks
  • Justcurious
    Justcurious about 7 years
    setNestedScrollingEnabled(false) Solved my issue of scroll
  • Sreeram Sunkara
    Sreeram Sunkara over 6 years
    This 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
    brijexecon over 6 years
    Just added nestedScrollingEnabled="false" in recyclerview It worked for me. Thanks for ur support.
  • Gökberk Yağcı
    Gökberk Yağcı over 3 years
    It is working for me too. But i do not understand how it exactly solve this issue ? What is the solution behind it ?