Recyclerview inside Nested Scrollview scroll but does not fast scroll like normal Recyclerview or Nested Scrollview

AndroidAndroid RecyclerviewAndroid Nestedscrollview

Android Problem Overview


I am using RecyclerView inside NestedScrollView and it works. But when I use RecyclerView inside LinearLayout or something, it scroll in various speed depending on gesture. The scroll listen to gesture and if I slide up only a bit, then it scroll a little bit while if I slide up really fast, then it scroll really fast. Now my problem is that RecyclerView inside NestedScrollView certainly scroll but fast scroll does not work. However I slide up fast or slow, RecyclerView or NestedScrollView only scroll a little bit.

How can I make my NestedScrollView or RecyclerView inside that scroll view scroll in various speed?

Android Solutions


Solution 1 - Android

try

recyclerView.setNestedScrollingEnabled(false);

Solution 2 - Android

By default setNestedScrollingEnabled works only after API-21.

You can use ViewCompat.setNestedScrollingEnabled(recyclerView, false); to disable nested scrolling for before and after API-21(Lollipop). Link to documentation.

Solution 3 - Android

I was working on android 16 where this was not possible to use setNestedSCrollEnabled method,

What I end up doing to stop RecyclerView from handling Scrolls.

Like in LinerLayoutManager i made canScrollHorizontally, canScrollVertically to return false by default.

myRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false){
            @Override
            public boolean canScrollHorizontally() {
                return false;
            }

            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });

Solution 4 - Android

After several iterations, I came up with a solution.

  1. If you are using RecyclerView, then:

     recyclerView.setNestedScrollingEnabled(false);
    
  2. If you are using LinearLayout inside NestedScrollingView, take the LinearLayout inside a normal ScrollView and then set its scrolling to

     scrollView.setNestedScrollingEnabled(false);
    

Solution 5 - Android

android:overScrollMode="never

  <android.support.v4.widget.NestedScrollView
    android:id="@+id/nestedScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:overScrollMode="never">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>
 </android.support.v4.widget.NestedScrollView>

Solution 6 - Android

You can use ScrollView with ExtendRecyclerView class that overrides the onMeasure method. That works for me!

@Override
protected void onMeasure(int widthSpec, int heightSpec) {
    int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
    super.onMeasure(widthSpec, expandSpec);
}

Solution 7 - Android

recyclerView.setNestedScrollingEnabled(false);

Will be useful sometimes.But it is not advisable for all the times.because it disables view recycling feature in recylcer view.

Alternatives:

Try CollapsiveToolbarLayout with Recycler view. put other views in collapsiveTollbar layout.

Solution 8 - Android

I also met this problem. And upgrade to 26.1.0 fix it.

Solution 9 - Android

In My Case i placed all images in drawable folder insted of drawable-xxxhdpi folder thats why my screen UI is lagging.

Solution 10 - Android

This is WAI. The NestedScrollView measures its children with the Spec "Unspecified". The child can grow as much as it wants too.

This essentially equates the height of NSV and RV. So as far as the RV is concerned, it believes that it is completely displayed.

Wrap your RV with an LL and give your RV a height. The LL would not set the measure spec to be UNSPECIFIED so the RV would correctly scroll within its set height of whatever DPs you provide.

The only downside of this method is that you will not be able to do a match parent on your RV.

Solution 11 - Android

You should wrap recycler view in any layout like LinearLayout and set RecyclerView size to constant, like 800dp. This will enable smooth scroll and recycler view will still recycler views during scroll.

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                                xmlns:app="http://schemas.android.com/apk/res-auto"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="800dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</LinearLayout>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAung Si Min HtetView Question on Stackoverflow
Solution 1 - AndroidYang PeiyongView Answer on Stackoverflow
Solution 2 - AndroidHemant KaushikView Answer on Stackoverflow
Solution 3 - AndroidZain AliView Answer on Stackoverflow
Solution 4 - AndroidSarthak GandhiView Answer on Stackoverflow
Solution 5 - AndroidMaryam AzhdariView Answer on Stackoverflow
Solution 6 - AndroidQuý Nguyễn NamView Answer on Stackoverflow
Solution 7 - AndroidRajesh.kView Answer on Stackoverflow
Solution 8 - AndroidlinkaipengView Answer on Stackoverflow
Solution 9 - AndroidMayuresh DeshmukhView Answer on Stackoverflow
Solution 10 - AndroidMuhammad Ahmed AbuTalibView Answer on Stackoverflow
Solution 11 - AndroidThrorView Answer on Stackoverflow