Reputation: 73
How to hide toolbar on scroll in recyclerview, which is located in fragment in viewpager, if using new design support library?
<android.support.v4.widget.DrawerLayout
... >
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<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.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
...
android:minHeight="?actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
... />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
... />
</android.support.v4.widget.DrawerLayout>
Upvotes: 1
Views: 1124
Reputation: 345
Your layout appears to be fine. You should however also add the behaviour inside your RecyclerView (I suppose it is in a Fragment that is later added to the ViewPager):
app:layout_behavior="@string/appbar_scrolling_view_behavior"
and most importantly and as stated by this other SO answer, don't forget to update your build tools to 22 and your gradle references to at least v 22.20 of both the component and the Design Support Library:
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
Check out this for a complete tutorial.
Upvotes: 3
Reputation: 18725
There is a control already built into the library called CollapsingToolbarLayout. It is already designed to collapse on scroll, and will include Paralax, text, and fading effects (so you should use it).
Upvotes: -1