CoordinatorLayout using the ViewPager's RecyclerView
Chris Banes has posted a sample on Github which shows exactly what you want to do.
Here is the xml file that defines how one can indirectly attach a coordinator layout to the viewpager's fragments.
<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="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</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.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_done" />
</android.support.design.widget.CoordinatorLayout>
The idea is to let the viewpager have the layout_behavior attribute.
Coordinator layout with viewpager, scroll doesn't work
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="200dp"/>
<!--Wrap content will not work here you have to give fix height-->
</androidx.core.widget.NestedScrollView>
Using coordinator layout with recycler view
The app bar/toolbar part looks okay. However, you have a RecyclerView
wrapped in a NestedScrollView
and that is unnecessary.
Remove the NestedScrollView
entirely and declare your RecyclerView
like this:
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:id="@+id/list_hotels"
android:background="@color/back1"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
If you still have problems, update your question with the new XML layout.
Related Topics
How to Get Thumbnail for Video in My /Sdcard/Android/Data/Mypackage/Files Folder
How to Add Background Image to Activity
How to Find The Amount of Free Storage (Disk Space) Left on Android
What Are Intent-Filters in Android
How to Call a Wcf Service Using Ksoap2 on Android
How to Change Android:Windowsoftinputmode Value from Java Class
Designing Android Apps for Tablets
How to Change Option Menu Icon in The Action Bar
Android Serversocket Programming with Jcifs Streaming Files
Music Player Control in Notification
Android 4.4.2 - Java.Lang.Runtimeexception: Performing Stop of Activity That Is Not Resumed
Asynctaskloader Basic Example. (Android)
Stuck with Gradle Build Running
How to Close Android Soft Keyboard Programmatically
How to Hide The Soft-Key Bar on Android Phone