[英]Hide toolbar on scroll design support library
How to hide toolbar on scroll in recyclerview, which is located in fragment in viewpager, if using new design support library? 如果使用新的设计支持库,如何在repageerview的滚动条中隐藏在viewpager片段中的滚动条上的工具栏?
<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>
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):
但是,您还应该在RecyclerView内部添加行为(我想它是在一个Fragment中,然后将其添加到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: 最重要的是,正如另一个SO回答所指出的,不要忘记将构建工具更新为22,并且gradle引用至少要对组件和设计支持库的v 22.20版本进行更新:
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
There is a control already built into the library called CollapsingToolbarLayout . 库中已经内置了一个名为CollapsingToolbarLayout的控件。 It is already designed to collapse on scroll, and will include Paralax, text, and fading effects (so you should use it).
它已经设计成可以在滚动时折叠,并且将包括Paralax,文本和淡入淡出效果(因此您应该使用它)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.