如果使用新的设计支持库,如何在位于 viewpager 的 fragment 中的 recyclerview 中隐藏滚动工具栏?
<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>
最佳答案
您的布局看起来不错。但是,您还应该在 RecyclerView 中添加行为(我想它在稍后添加到 ViewPager 的 fragment 中):
app:layout_behavior="@string/appbar_scrolling_view_behavior"
最重要的是,如 this other SO answer 所述,不要忘记将您的构建工具更新为 22,并将您的 gradle 引用至少更新到组件和设计支持库的 v 22.20:
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
查看 this获取完整教程。
关于java - 在滚动设计支持库上隐藏工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30715089/