gpt4 book ai didi

android - Material 设计 layout_scrollFlags 含义

转载 作者:IT王子 更新时间:2023-10-28 23:59:12 25 4
gpt4 key购买 nike

我发现我们可以通过 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,它的布局有一个Recycle View,在RecycleView 下方有一个edittext。首先我想知道这个标志是什么意思

谷歌说:

  • SCROLL_FLAG_ENTER_ALWAYS
    进入(在屏幕上滚动)时,无论 ScrollView 是否也在滚动, View 都会在任何向下滚动事件上滚动。
  • SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED
    'enterAlways' 的附加标志,它将返回 View 修改为仅最初滚动回其折叠高度。
  • SCROLL_FLAG_EXIT_UNTIL_COLLAPSED
    退出(滚动屏幕)时, View 将滚动直到它“折叠”。
  • SCROLL_FLAG_SCROLL
    View 的滚动与滚动事件直接相关。
  • SCROLL_FLAG_SNAP
    在滚动结束时,如果 View 仅部分可见,则它将被捕捉并滚动到最近的边缘。

我随机更改了这个标志,在某些情况下,我的编辑文本消失了,直到我向上滚动工具栏然后出现编辑。我读了谷歌文档但我无法得到它。我想简单的理解一下。

最佳答案

我不知道我的回答是否仍然有意义,但尽管如此。实际上,文档足以理解周围发生的事情,您只需要玩一点。
app:layout_scrollFlags 属性中使用的 scroll 标志必须启用才能使任何滚动效果生效。此标志必须与 enterAlwaysenterAlwaysCollapsedexitUntilCollapsedsnap 一起启用:

  • enterAlways: View 将在向上滚动时变为可见。当从列表底部滚动并希望在向上滚动时立即显示工具栏时,此标志很有用。
  • enterAlwaysCollapsed:正常情况下,当只使用enterAlways时,Toolbar会随着向下滚动而继续展开。假设声明了enterAlways并且你已经指定了minHeight,你也可以指定enterAlwaysCollapsed。使用此设置时,您的 View 将仅显示在此最小高度。只有当滚动到顶部时, View 才会展开到其全高
  • exitUntilCollapsed:设置滚动标志时,向下滚动通常会导致整个内容移动。通过指定minHeight和exitUntilCollapsed,将在其余部分之前达到Toolbar的最小高度内容开始滚动并退出屏幕
  • snap:使用此选项将确定当 View 仅部分缩小时要执行的操作。如果滚动结束并且 View 大小已减小到其原始大小的 50% 以下,则此 View 返回其原始大小。如果大小大于其大小的 50%,它将完全消失。

请看一下 blog应该很有帮助。

更新:还有另一个 article (edit: now necessary to sign in to Medium account)关于滚动标志。非常感谢 Martin Ombura Jr !

关于android - Material 设计 layout_scrollFlags 含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35286582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com