如何停止CollapsingToolbarLayout的滚动,以便它不会完全折叠

3

大家好,请问如何停止它?请看下面的截图。

enter image description here

向上滚动后,它应该在应用程序工具栏以下最少200dp处停止。

enter image description here


在工具栏下添加多个项目,但由于只有一个项目,因此它不会滚动! - Michele Lacorte
请您能否清楚地解释一下。 - user2100931
抱歉,我误解了您的请求,您希望工具栏停在200dp的右侧? - Michele Lacorte
但是你做了什么?你能分享一下代码吗? - Kavin Prabhu
你已经实现了这个吗? - Kavin Prabhu
2个回答

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)。希望这是您要寻找的内容!


非常感谢。您能否避免并删除使用硬编码的值。 - user2100931
我在谈论的是工具栏和AppBarLayout的高度。我们能否动态地进行调整呢? - user2100931
我已经在dimens.xml中使用了它们,所以它们不是硬编码的!我在各种值文件夹中的dimens.xml中具有不同的值。 - Kavin Prabhu
很好,谢谢。我没有注意到它。我只是在检查它,但它运行良好。 - user2100931

1
设置最小折叠高度。
android:minHeight="200dp"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接