Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recyclerview with inside nested scrollview?

I am using multiple View-holder inside recycler which placed inside nested scroll view,There is a change in Natural behaviour of onBindViewHolder() Recycler view because of Nested Scroll,getItemViewType() all items are called inside onBindViewHolder() when initiate recycler adapter,For Example I have 20 Items means in normal scenario only three items called when initiate,but in case of nested scroll view all 20 views create on first load.

Xml File

<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/main_content"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/light_gray_vd">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="@color/primaryColor"
            app:expandedTitleMarginEnd="16dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax">

                <include
                    android:id="@+id/inc_gallery"
                    layout="@layout/proj_galery_new"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />

            </FrameLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar1"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="top"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

                <include
                    android:id="@+id/toolbar_header_view"
                    layout="@layout/header_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:visibility="gone" />
            </android.support.v7.widget.Toolbar>

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

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

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/vde_mv_scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <FrameLayout
            android:id="@+id/rlCollapseScroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <android.support.v7.widget.RecyclerView
                android:id="@+id/view_recycler"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

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



        </FrameLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
like image 977
appukrb Avatar asked Oct 31 '22 09:10

appukrb


1 Answers

remove NestedScrollView and frameLayout, and set app:layout_behavior="@string/appbar_scrolling_view_behavior" for recycleView like this:

<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/main_content"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/light_gray_vd">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="@color/primaryColor"
            app:expandedTitleMarginEnd="16dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax">

                <include
                    android:id="@+id/inc_gallery"
                    layout="@layout/proj_galery_new"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />

            </FrameLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar1"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="top"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

                <include
                    android:id="@+id/toolbar_header_view"
                    layout="@layout/header_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:visibility="gone" />
            </android.support.v7.widget.Toolbar>

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

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

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

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

</android.support.design.widget.CoordinatorLayout>
like image 116
javad Avatar answered Nov 08 '22 05:11

javad