1
I have a Fragment
with a CoordinatorLayout
and a FrameLayout
to popular with other Fragments. One of these Fragments contains a RecyclerView
.
I’d like to know how to do the RecyclerView
work with the CoordinatorLayout
each one of which is in a file. I have tried to put a NestedScrollView
as the father of Fragment
who has the RecyclerView
, but when I do onBindViewHolder
of the Adapter of RecyclerView
is called for all elements and then I can not do paginated search to fill the RecyclerView
.
Main Fragment code containing Coordinatorlayout:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@color/background">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:elevation="0dp"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"/>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:background="@color/colorTab"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container_restaurant"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
Fragment code that has Recyclerview:
<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"
android:fillViewport="true"
android:background="@color/background"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/my_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.NestedScrollView>
Thus the scroll even works but the onBindViewHolder
is called for all items in the list, including those that are not being displayed. If I put a LinearLayout
instead of NestedScrollView
, the onBindViewHolder
works the right way but the behavior of scroll @string/appbar_scrolling_view_behavior
with the CoordinatorLayout
doesn’t work.
Have you ever tried to put Nestedscrollview as the father of
container_restaurant
?– Max Fratane