【问题标题】:Make collapsible toolbar automatically collapse/expand使可折叠工具栏自动折叠/展开
【发布时间】:2016-08-19 06:21:18
【问题描述】:

当垂直偏移超过特定阈值时,如何使android中的可折叠工具栏自动折叠/展开?

如,如果垂直偏移超过getScrollRange() 的半点,则可折叠工具栏应自动展开,低于该阈值时应折叠。

【问题讨论】:

    标签: android android-collapsingtoolbarlayout


    【解决方案1】:

    您可以使用snap 标志,如下所示:

    <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/collapsing_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fitsSystemWindows="true"
                    app:contentScrim="?attr/colorPrimary"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
    

    Example Gif

    使用此选项将确定仅在视图部分缩小时要执行的操作。如果滚动结束并且视图大小已减小到其原始大小的 50% 以下,则此视图返回其原始大小。如果大小大于其大小的 50%,它将完全消失。

    您可以在此处阅读有关 CollapsingToolbarLayout 滚动标志的更多信息:
    https://guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout

    【讨论】:

      【解决方案2】:

      只需使用 'snap' 选项即可获得所需的输出。设置折叠工具栏布局滚动标志为:

      app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"

      snap:此选项将确定当视图仅部分缩小时要执行的操作。如果滚动结束并且视图大小已减小到其原始大小的 50% 以下,则此视图返回其原始大小。如果大小大于其大小的 50%,它将完全消失。

      我希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-13
        相关资源
        最近更新 更多