1

I have a RecyclerView with a fixed height inside a NestedScrollView with a few other layouts inside it. The recycler view won't scroll, but it scrolls fine if I set its height to wrap_content.

I cannot make the RecyclerView use wrap_content because there is an issue with EndlessRecyclerViewScrollListener that it keeps loading data from the server and pushing it into my Adapter even if the user has not scrolled down at all.

Most are suggesting to set nested scrolling to false, but if I disable nested scrolling, the NestedScrollView does not allow me to scroll my RecyclerView. But if I leave nested scrolling enabled, the scroll view does not scroll unless I start touching from outside the RecyclerView.

My layout code:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/scoop_background"
tools:context=".module.scoop.timeline.ScoopTimelineFragment">

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

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="92dp">

        <ImageView
            android:id="@+id/ivTimelineBanner"
            android:layout_width="match_parent"
            android:layout_height="92dp"
            android:layout_margin="0dp"
            android:clickable="true"
            android:padding="0dp"
            android:scaleType="fitXY"
            android:src="@drawable/banner_placeholder" />

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center_vertical"
                android:orientation="vertical"
                android:paddingLeft="92dp">

                <TextView
                    android:id="@+id/tvGroupMembership"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/text_content" />

                <TextView
                    android:id="@+id/tvGroupName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/text_header"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/tvGroupMemberCount"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/text_content" />

            </LinearLayout>

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:background="@null"
                android:paddingStart="@dimen/divider_normal"
                android:paddingEnd="@dimen/divider_normal"
                android:src="@drawable/ic_chevron_right_white_24dp" />

        </LinearLayout>

    </FrameLayout>

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefreshLayoutTimeline"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

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

                <android.support.v7.widget.CardView
                    android:id="@+id/cvCreateScoop"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/divider_small"
                    android:layout_marginRight="@dimen/divider_small"
                    android:clickable="true"
                    android:focusable="true"
                    android:foreground="?attr/selectableItemBackground"
                    app:cardCornerRadius="8dp"
                    app:cardUseCompatPadding="true">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:padding="@dimen/divider_normal">

                        <ImageView
                            android:layout_width="32dp"
                            android:layout_height="32dp"
                            android:src="@drawable/svg_nav_create_scoop" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:layout_weight="1"
                            android:gravity="center_vertical"
                            android:paddingStart="@dimen/divider_normal"
                            android:text="What's on your mind?"
                            android:textSize="@dimen/text_content" />

                        <ImageView
                            android:layout_width="32dp"
                            android:layout_height="32dp"
                            android:padding="@dimen/divider_xsmall"
                            android:src="@drawable/svg_insert_image" />
                    </LinearLayout>

                </android.support.v7.widget.CardView>

                <RelativeLayout
                    android:id="@+id/relativeLayout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/rv"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:clipToPadding="false"
                        android:overScrollMode="never"
                        android:nestedScrollingEnabled="false"
                        android:paddingLeft="8dp"
                        android:paddingRight="8dp"
                        android:paddingBottom="4dp">

                    </android.support.v7.widget.RecyclerView>


                </RelativeLayout>

            </LinearLayout>

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

    </android.support.v4.widget.SwipeRefreshLayout>

</LinearLayout>

What do I have to modify so that the RecyclerView is scrollable, but the whole NestedScrollView also scrolls along with it, so that if the user is scrolling back up (swiping from top to bottom), the RecyclerView will scroll along with the NestedScrollView, which will bring the layouts above RecyclerView.

To visualize:

The layout I'm trying to achieve is similar to that of facebook's. When you scroll down, the timeline will scroll down, and the search bar with the messenger icon at the top is also scrolled so that it is hidden when scrolling down. When you scroll up, the timeline is being scrolled back up, and showing the search bar again.

Rick
  • 1,197
  • 2
  • 10
  • 22

1 Answers1

0

I decided to do it differently because I wasn't able to solve it with this method. Instead, I used a CollapsingToolbar and put the other layouts inside it, then removing its background so it does not look like a toolbar, and it seamlessly does what I wanted to, just with a different implementation.

Rick
  • 1,197
  • 2
  • 10
  • 22