【发布时间】:2017-01-23 22:41:38
【问题描述】:
我试图找到有相同问题的人,但我真的不知道要搜索什么。如果其他人发现类似的问题,请告诉我!
我已经实现了设计库中的工具栏,如下所示:
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<include layout="@layout/toolbar" />
<android.support.design.widget.TabLayout
android:id="@+id/mainTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabGravity="fill" />
</android.support.design.widget.AppBarLayout>
和工具栏布局:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/mainToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" />
AppBarLayout 是 CoordinatorLayout 的直接子级。在 AppBar 下方,我有一个 RecyclerView,它可以在向上滚动时正确地让 AppBar 折叠。
但是,我可以直接在 AppBar 上按下,然后向上移动手指,这样工具栏就会折叠,即使我的 RecyclerView 完全是空的。我可以通过再次向下滚动工具栏来再次展开它。滚动 RecyclerView 所在的位置时不会发生此行为。
我希望我的问题是可以理解的。我正在使用支持库的 25.1 版。 谢谢!
编辑:我尝试了以下解决方案。没有改变任何东西。在下面我添加了一个视频来显示我的问题。因此,这实际上是关于屏幕未满时的情况(因此 RecyclerView 中的任何元素都不会离开屏幕):如果是这种情况,我根本不希望工具栏隐藏。换句话说:仅当 RecyclerView 中的任何元素离开屏幕时才隐藏工具栏。
https://drive.google.com/file/d/0Bzrw-IuZ9USuMURVVkRfb3dkRTQ/view?usp=sharing
如果我这边需要更多代码,请告知。
【问题讨论】:
-
我认为您正在寻找投掷行为。谷歌它你会找到现成的代码
-
我不认为这是我的问题。如果你看视频(第一部分): RecyclerView 没有离开屏幕,但工具栏在向上滚动时仍然隐藏。我不想要那个。 @SouravGanguly
标签: android android-support-library android-toolbar