I have a ViewPager inside an Activity which shows two Fragments.
The activity has a TabLayout and a CollapsingToolbarLayout. The CollapsingToolbarLayout is nested inside the AppBarLayout with an ImageView to produce a parallax effect. The TabLayout is outside the AppBarLayout inside a LinearLayout with the ViewPager. Then there is a FrameLayout as well to show another Fragment over the ViewPager when the user clicks a button to show that Fragment.
The problem is that when you scroll the RecyclerView inside the Fragment that overlays on top of the ViewPager the Activity also scrolls and does the parallax effect. Essentially it scrolls both the RecyclerView inside the Fragment and the content inside the ViewPager as well.
Is there a way to stop scrolling for the CollapsingToolbarLayout and only scroll content in the overlay Fragment when the user sees that Fragment?
This is what my XML Hierarchy looks like:
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.design.widget.CollapsingToolbarLayout
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<android.support.design.widget.TabLayout />
<!-- Two fragments inside ViewPager each containing a RecyclerView -->
<android.support.v4.view.ViewPager />
</LinearLayout>
<!-- User Clicks a button and fragment is added to this framelayout -->
<!-- This fragment overlays on top of the entire Activity layout -->
<!-- This fragment also contains a recyclerview -->
<FrameLayout/>
</android.support.design.widget.CoordinatorLayout>