2

I have a collapsing toolbar with ViewPager inside it. ViewPager has 3 fragments, one of which has a RecyclerView inside it. ColllapsingToolbar works fine for the other two fragments but it doesn't work as expected in the fragment with RecyclerView.

I am using recyclerview version v7 23.2.1. My recylcerView has custom items (each item contains a parent cardview).

I have seen other posts related to this issue but none of them were of great help.

My Fragment layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:layout_gravity="fill_vertical"
android:background="@color/color_ee"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/topSubmissionsList"
            android:layout_below="@+id/top_bar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

My RecyclerView Item code:

<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:layout_gravity="fill_vertical"
android:background="@color/color_ee"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="15dip">

<!-- My Custom Content -->

</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
Pareek
  • 153
  • 11

1 Answers1

0

You don't need to put the layout in NestedScrollView which you are inflating inside RecylcerView. I mean your CardView.

It should look like this

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="15dip">

<!-- My Custom Content -->

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

UPDATE:

Your RecyclerView should be like this

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

the key thing here is app:layout_behavior="@string/appbar_scrolling_view_behavior" it will make your scrolling fine.

Atiq
  • 14,435
  • 6
  • 54
  • 69