I don't understand why recyclerview in nestedscrollview load all data

1.4k views Asked by At

I am worried about RecyclerView in NestedScrollView loading all data. I just want RecyclerView to load a part of data as many as visible on screen, not all data.

The main view of my app consists of CollapsingToolbarLayout a TabLayout, and a ViewPager.

One fragment of ViewPager has a NestedScrollview for collapsing up CollapsingToolbarLayout.

Also, that fragment (of FrameLayout of second xml) has the real RecyclerView.

I don't understand why the RecyclerView in NestedScrollView is loading all the data. Once I remove the NestedScrollView, all works good. But I think I might use NestedScrollView for collapsing up CollapsingToolbarLayout. How can I resolve it? Thank you in advance

activity_main.xml

    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/coordinatorLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsingToolbarLayout"
                android:layout_width="match_parent"
                android:layout_height="@dimen/app_bar_height"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                ...

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:minHeight="?attr/actionBarSize"
                    android:gravity="center_vertical"
                    android:layout_marginTop="16dp"
                    android:layout_marginBottom="8dp"
                    android:fitsSystemWindows="true"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

                <android.support.design.widget.TabLayout
                    android:id="@+id/tabLayout"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:layout_gravity="bottom"
                    android:fitsSystemWindows="true"
                    app:layout_collapseMode="pin"
                    app:tabIndicatorColor="?attr/colorAccent"
                    app:tabIndicatorHeight="3dp"/>

            </android.support.design.widget.CollapsingToolbarLayout>


        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#fff"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/navigation_drawer_items"
        app:itemIconTint="?attr/colorPrimary"
        app:itemTextColor="@color/black">

    </android.support.design.widget.NavigationView>

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

fragment_for_viewpager.xml

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

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

            <android.support.design.widget.TabLayout
                android:id="@+id/rankSortTabLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"
                app:tabIndicatorColor="@color/lightgrey"
                app:tabIndicatorHeight="1dp"/>
            <FrameLayout
                android:id="@+id/rank_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            </FrameLayout>

        </LinearLayout>

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

recyclerview_subfragment.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rankSortRecyclerView"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

There are 0 answers