99

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?

Vasily Kabunov
  • 5,179
  • 12
  • 41
  • 46
Aung Si Min Htet
  • 1,084
  • 2
  • 9
  • 12
  • 3
    recyclerView.setNestedScrollingEnabled(false); This really works !! – Aung Si Min Htet Jun 23 '16 at 02:02
  • https://stackoverflow.com/questions/27083091/recyclerview-inside-scrollview-is-not-working/45466603#45466603 Solution can be found here. – maruti060385 Aug 04 '17 at 15:13
  • Please use [open fun setNestedScrollingEnabled(enabled: Boolean): Unit](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView#setnestedscrollingenabled) Hope it will help you – Int0TheRainb0w Jun 12 '20 at 10:43

11 Answers11

267

try

recyclerView.setNestedScrollingEnabled(false);
Yang Peiyong
  • 10,618
  • 2
  • 19
  • 14
  • 16
    But by this setting, recyclerview does not recycle views! what's your idea about it? – MAY3AM Jun 03 '16 at 12:46
  • Actually I am adding two or more recycler views with different layout managers (such as Linear Layout and Grid Layout) inside my layout which also include banner, and other views. So to handle the recycler view like that, putting all of these inside the Nested Scroll View fix for me. – Aung Si Min Htet Jun 23 '16 at 01:59
  • 27
    I dont know how this answer got so many upvotes. If disabling nested scroll then it is defeating it's purpose. What if I want to use nested scrolls and recycler?? Something like CoordinatorLayout, AppBarLayout and RecyclerView?? – Jimit Patel Dec 13 '16 at 09:09
  • Thanks @JimitPatel , this is exactly my issue at the moment. I have a recycleview within a nestedscroll view and I can't scroll.http://stackoverflow.com/questions/41259756/recyclerview-scroll-dosent-work-with-nestedscrollview/ – Karoly Jan 05 '17 at 14:57
  • 1
    @Karoly need to customize nested scrolls... I've that... Will post that in few hours... Currently, I'm traveling. I faced that issue in parallax effect with recycler view after toolbar. – Jimit Patel Jan 05 '17 at 15:09
  • @JimitPatel thanks, looking forward to it! So you saying I have to write my own RecycleView, right ? – Karoly Jan 05 '17 at 15:24
  • @Karoly check out in your earlier link. I have provided solution there – Jimit Patel Jan 05 '17 at 17:01
  • @Jimit Patel did you get chance to post about issue you mentioned? I'd appreciate if you share the link. I'm currently experiencing similar problem. Recycler view part scroll works fine but when it scrolls up it stops scroll at recycler view area and have to scroll up again to expand the collapsinglayouttoolbar....... – Chaesung 'Jaesung' Yoon Feb 05 '17 at 09:24
  • @Chaesung'Jaesung'Yoon check this link http://stackoverflow.com/a/41490571/842607 the additional info will be of your interest I guess – Jimit Patel Feb 05 '17 at 09:53
  • @Yang Thanks a lot friend for helping out – Saksham Khurana Jun 23 '17 at 13:50
  • This does solve the problem, but as others have commented, if this disables recycling, it could use more RAM. But instead of just telling why you cannot understand why this answer got so many upvotes, please add your answer that solves this problem but not disabling recycling. – Damn Vegetables Dec 26 '17 at 16:41
  • Finally I Solved the problem using ur soln:) Thanks alot @Yang – Sandy May 01 '20 at 08:06
53

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.

Zain
  • 13,030
  • 5
  • 26
  • 49
Hemant Kaushik
  • 1,470
  • 13
  • 20
21

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;
            }
        });
Zain Ali
  • 13,997
  • 14
  • 87
  • 103
10

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);
    
Pang
  • 8,605
  • 144
  • 77
  • 113
Sarthak Gandhi
  • 1,966
  • 1
  • 12
  • 22
3

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>
Maryam Azhdari
  • 867
  • 8
  • 8
1

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);
}
1
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.

Rajesh.k
  • 1,846
  • 1
  • 13
  • 17
-1

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

linkaipeng
  • 305
  • 3
  • 7
-2

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

-3

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.

Muhammad Ahmed AbuTalib
  • 3,544
  • 3
  • 30
  • 46
-4

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>

Thror
  • 397
  • 3
  • 4
  • 2
    This is a good answer because it points the way to fixing the fling scroll issue without breaking the RecyclerView's main benefit, loading only the visible views and recycling them when they are scrolled out of sight. People may have down-voted it because a fixed value like 800dp is not going to work in all screen sizes and orientations, but the layout_height value could be calculated and set programmatically - a bit messy, but it solves both issues. – jk7 Oct 13 '17 at 23:48