2
votes

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.

2

2 Answers

0
votes

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" />
0
votes

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"
        ...