我发现我们可以使用酷标记来滚动工具栏甚至内容,方法是使用layout_scrollFlags
。就我而言,我有这样的布局:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="snap"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill" />
</android.support.design.widget.AppBarLayout>
<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.CoordinatorLayout>
我的一个标签是fragment
,其布局在RecycleView下面有一个Recycle View
,edittext
。首先,我想知道这个标志意味着什么
我随机更改了这个标志,在某些情况下,我的编辑文本消失,直到我向上滚动工具栏然后编辑出现。我看了谷歌文件 但我不能很好。我想用简单的术语来理解它。
答案 0 :(得分:75)
我不知道我的答案是否仍然有用,但不过。实际上,文档足以理解周围的事情,你只需要玩一点点。
必须启用属性app:layout_scrollFlags
中使用的滚动标志才能使任何滚动效果生效。必须同时启用此标记enterAlways
,enterAlwaysCollapsed
,exitUntilCollapsed
或snap
:
enterAlways
:向上滚动时视图将变为可见。当从列表底部滚动并希望在滚动时立即公开工具栏时,此标志非常有用。enterAlwaysCollapsed
:通常情况下,当只使用enterAlways时,工具栏会在您向下滚动时继续展开。当您声明enterAlways并指定了minHeight时,您还可以指定enterAlwaysCollapsed。使用此设置时,您的视图将仅显示在此最小高度。只有当滚动到达顶部时,视图才会扩展到其全高exitUntilCollapsed
:设置滚动标记后,向下滚动通常会导致整个内容移动。通过指定minHeight和exitUntilCollapsed,将在其余内容开始之前达到工具栏的最小高度滚动并退出屏幕snap
:使用此选项将确定仅在部分缩小视图时要执行的操作。如果滚动结束并且视图大小已减小到原始视图的小于50%,则此视图将恢复为其原始大小。如果尺寸大于其尺寸的50%,它将完全消失。请查看此blog,这应该非常有帮助。