appukrb February 2016

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_        

Answers


Hein February 2016

The issue is both Recyclerview and NestedScrollview are scrollable. By removing one, you should be able to achieve the effect you wanted.

So, try using only Recyclerview without putting it inside NestedScrollView. 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"
      


javadaskari February 2016

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:l 


mixel March 2016

I also had same issue after Android Support Library 23.2.0 update.

Set RecyclerView's android:layout_height to match_parent.

And disable new automeasure feature (read more):

LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), 
    LinearLayoutManager.VERTICAL, false);
layoutManager.setAutoMeasureEnabled(false);
recyclerView.setLayoutManager(layoutManager);

Post Status

Asked in February 2016
Viewed 3,716 times
Voted 8
Answered 3 times

Search




Leave an answer