2

When I'm scrolling down, the items above the RecyclerView does not scroll unless I start touching from the layout above, and it only scrolls down when I have reached the end of the RecyclerView.

<NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout>
        <Some other items.../>
    </LinearLayout>

    <RecyclerView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"/>
</NestedScrollView>

Note: I actually use a fixed size for the RecyclerView, setting it via the code below:

float height_recyclerview = (ScreenUtil.getHeight(context) - (height_banner + height_bottom_navigation + height_create_post));
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) height_recyclerview);
rv.setLayoutParams(layoutParams);

Why do I use fixed size if it works smoothly with wrap_content?

  • I will be displaying possibly thousands of items that may have images, which will hurt performance if it does not actually do recycling because of the issue that the RecyclerView is inside the NestedScrollView
  • I have implemented an EndlessRecyclerViewScrollListener which has an issue that it keeps loading more data from server continuously if implemented with a RecyclerView that is within whatever scrollable view, or if it is in a scrollable view, but does not have a fixed height, even if you are not scrolling down.

I have tried the following:

  • set nested scrolling to false on the recycler view
  • try using scroll view instead of nested scroll view
  • a bunch of other code related to layouts and scrolling behaviors that others suggested which didn't work for me because I'm implementing it in a much more complicated layout and the fact that I use EndlessRecyclerViewScrollListener

What I want to fix?

I want to make the page scroll like a single page, not as a separate scrollable view.

Note that my recycler view has a fixed height that takes the entire screen's space meaning that its height is actually fit assuming that the linear layout above is not visible anymore if the user has scrolled down.

The ideal scenario is to make the scrollview scroll down first, to make the recycler view take the entire screen, so that the recyclerview will scroll however the user wants to.

Then the linearlayout above which should not be visible anymore if the recycler view has taken up all the space of the screen, should only show up if the recycler view has reached the top/first item, if the user keeps scrolling back up.

Rick
  • 1,197
  • 2
  • 10
  • 22

2 Answers2

0

Read this.

Add app:layout_behavior="@string/appbar_scrolling_view_behavior" to your recycler xml.

<android.support.v7.widget.RecyclerView
    android:id="@+id/conversation"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
Dmytro Ivanov
  • 1,189
  • 1
  • 7
  • 10
  • I did not disable nested scrolling. But my issue is that the layouts above the recycler view does not scroll accordingly. And.. If I disable the nested scrolling. The recycler view wont scroll at all. – Rick Dec 27 '18 at 18:28
  • Still works the same. My goal is to make the scrollview scroll down first, until the recyclerview fits the screen. So that my recyclerview will then scroll as the user wants it. And that the linearlayout above will only show again if the recyclerview reaches the top if the user keeps scrolling back up. – Rick Dec 27 '18 at 18:35
0

NestedScrollView Smooth Scrolling

recyclerView.isNestedScrollingEnabled = true

Do this programmatically

 <androidx.core.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="0dp"
        android:fillViewport="true"
        ...
Sharan
  • 1,032
  • 2
  • 14
  • 24
  • I have tried disabling nestedscrolling. And for some reason, the recycler view does not scroll at all because my recycler view has a fixed size. It does however scroll fine if the recyclerview is implemented with wrap_content. This is why I leave it enabled. And with nested scrolling enabled. I have the issue that I just posted above. – Rick Dec 27 '18 at 18:40
  • @Rick did you add that line? – Sharan Dec 27 '18 at 18:44
  • Yes I just tried it but sadly, it still doesnt work that way I want it. It's still the same – Rick Dec 27 '18 at 18:57
  • Okay what is your UI requirement? – Sharan Dec 27 '18 at 19:06
  • Make the nested scroll view scroll down even if I started touching inside the recyclerview. Because If I start touching inside the recyclerview and then scroll, only the recyclerview scrolls down. – Rick Dec 27 '18 at 19:10