【发布时间】:2019-02-19 18:43:37
【问题描述】:
我正在尝试根据RecyclerView 的滚动来隐藏和显示我的应用程序中的Toolbar。这个 gif 显示了我想要实现的目标。
我正在关注this tutorial,但没有得到我正在寻找的结果。这是我的活动布局:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:fitsSystemWindows="true">
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" />
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/header"
app:menu="@menu/drawer" />
</android.support.design.widget.CoordinatorLayout>
这是
Toolbar布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/ColorPrimary"
app:layout_scrollFlags="scroll|enterAlways" />
当我运行这段代码时,Toolbar 完全消失了。怎么了?
【问题讨论】:
-
我想学习第 3 部分的教程,因为我很快就会实现一个 FAB。 @SanketKachhela
-
这里也一样。我的应用程序具有几乎相同的结构并遵循相同的教程,但工具栏不会在滚动时隐藏。如果我能解决这个问题,我会告诉你的
-
我也有同样的问题。有人解决了吗?
-
@bashan 我设法解决了这个问题,并在一个单独的线程中解决了另一个问题,但我不记得这是多久以前的事了。不过,这可能会有所帮助,请查看stackoverflow.com/a/31241616/3038563
标签: android android-recyclerview android-toolbar