【问题标题】:How to Stop scroll on CollapsingToolbarLayout so it doesn't completely collapse如何在 CollapsingToolbarLayout 上停止滚动,使其不会完全折叠
【发布时间】:2016-01-06 15:38:59
【问题描述】:

您好 Everone,请您建议我如何阻止它。请看下面的屏幕截图。

向上滚动后,它应该停止在距离顶部至少 200dp 的应用工具栏下方

【问题讨论】:

  • 在工具栏下添加多个项目,它不会滚动,因为它只是一个项目!
  • 能否解释清楚。
  • 对不起,我误解了您的要求,您希望工具栏停止到 200dp 对吗?
  • 但是你做了什么?可以分享一下代码吗?
  • 你实现了吗?

标签: java android performance android-layout android-intent


【解决方案1】:

您可以执行以下操作

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height" //280dp
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="@dimen/my_toolbar_bar_height" //200dp
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay"/>

        </android.support.design.widget.CollapsingToolbarLayout>
   </android.support.design.widget.AppBarLayout>

<include layout="@layout/content_scrolling"/> // This is place holder for content/list

</android.support.design.widget.CoordinatorLayout>

AppBarLayout 高度将大于Toolbar 高度(在您的场景中,Toolbar 高度为200dp,所以我将AppBarLayout 保留为280dp)希望这就是您要找的!

【讨论】:

  • 非常感谢。您能否避免并使用硬编码值删除。
  • 工具栏和appbarlayout的高度我说的是。动态我们做不到。
  • 我在dimens.xml中使用过它们,所以没有硬编码!我的 dimens.xml 在不同的值文件夹中有不同的值。
  • 酷。谢谢。我没有观察到它。我只是在检查它。但它工作正常。
【解决方案2】:

设置最小折叠高度

android:minHeight="200dp"

【讨论】:

    猜你喜欢
    • 2015-10-14
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-06
    • 1970-01-01
    • 2020-06-13
    相关资源
    最近更新 更多