Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recyclerview with endless scrolling in nestedscrollview, triggers onScrolled

I have recyclerview in the nestedscrollview:

   <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

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

            <org.apmem.tools.layouts.FlowLayout
                android:id="@+id/filter_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/green_main"
                android:paddingLeft="@dimen/small_horizontal_margin"
                android:paddingRight="@dimen/small_horizontal_margin"
                />

            <android.support.v7.widget.RecyclerView
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipToPadding="false"
                android:scrollbars="vertical"
                android:paddingTop="@dimen/vertical_margin"/>

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

Recyclerview have OnScrollListener which is handling endless scrolling taken from this example: https://guides.codepath.com/android/Endless-Scrolling-with-AdapterViews-and-RecyclerView. However it seems like nestedscrollview is triggering onScrolled method, so whole list of items is loaded straight away.

Question: How I can prevent this beheviour?

Note, everything works perfect with recyclerview which isn't in nestedscrollview

like image 959
Eduards Denisjonoks Avatar asked May 06 '16 13:05

Eduards Denisjonoks


People also ask

How to use recyclerview inside nestedscrollview in Android?

This example demonstrates how do I use RecyclerView inside NestedScrollView in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Add the following dependency in the build.gradle (Module: app)

What is the use of nested scroll in Android?

This component allows you to not only scroll through views that extend the size of the device screen but also use complex layouts inside like the RecyclerView. When using a NestedScrollView in combination with RecyclerView, nested scrolling is enabled by default.

How to fix recyclerview's scrolling not working?

Although RecyclerView has a very good and smooth scrolling built-in, but when you put into any ScrollView, then your RecyclerView ’s scrolling will not work. For example, Now, the RecyclerView will not scroll. To fix that, you will have to use NestedScrollView instead of ScrollView like this:

How to make the recyclerview measure the height of nestscrollview?

You can use android:fillViewport="true" to make NestedScrollView measure the RecyclerView. The RecyclerView will fill the remaining height. so if you want to scroll the NestScrollView, you can set the RecyclerView's minHeight.


1 Answers

Try disabling nested scrolling on the RecyclerView:

recyclerView.setNestedScrollingEnabled(false);

Solved my issue with errant nested scrolling. Let me know if that helps.

like image 106
stack_overflow_user Avatar answered Sep 26 '22 04:09

stack_overflow_user