Reputation: 281
How can i make recycler view move along with viewpager The recycler view is not moving with the view pager . I have used a coordinator layout with a collapsing toolbar layout but still recycler view is srolling independently and not with the viewpager. The view pager is collapsing but only in that specific area..
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:scrollbars="vertical"
android:layout_height="150dp"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
android:id="@+id/slider_pager">
</android.support.v4.view.ViewPager>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:id="@+id/list_hotels"
android:background="@color/back1">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Please help me move them up and down together.
Upvotes: 3
Views: 2560
Reputation: 30985
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.
Upvotes: 3