我正在尝试使用CoordinatorLayout和CollapsingToolbarLayout创建一些组合布局。
在第一个状态,当我们在最顶层的页面上,并且还没有滚动时,我希望工具栏如下所示(是的,我做到了):
在第二种状态下,当开始向下滚动时,图像和工具栏应该消失,如下所示(仅显示选项卡):
在最后一个状态中,一旦我在列表中的某个点(但不是列表的顶部),我想开始向上滚动,一旦我开始向上滚动,我想要工具栏(而不是图像中消耗的工具栏)开始哇哇,如下图所示(如果没有到达列表的顶部,图像将不会显示,只有工具栏):
我能够实现第一个状态,但另一个状态是有问题的,一旦工具栏在CollapsingToolbarLayout中实现,我在CollapsingToolbarLayout组件之外可以用它做的灵活性不明确。我无法隐藏工具栏,如果我这样做,那么只有在我到达顶部时它才会显示。
无论如何,我当前的XML(如下所示)处于第一张图片实现的状态,但是一旦我开始向下滚动,工具栏就会保持在顶部并且不会隐藏。注意:我必须告诉工具栏保持“pin”,因为如果我没有,那么工具栏内的信息就会消失,只有一个空的工具栏会显示(这是另一个帖子,但是知道为什么会发生这种情况仍然很有趣?) 。
这是我当前的xml:
android:id="@+id/benefit_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/app_bar_material_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:id="@+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
android:id="@+id/toolbar_search_container"
layout="@layout/search_box"
android:layout_height="192dp"
android:layout_width="match_parent"
app:layout_collapseMode="parallax"
/>
android:id="@+id/toolbar_benefit"
layout="@layout/toolbar_main"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:contentScrim="?attr/colorPrimary"
/>
android:id="@+id/benefit_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primaryColor"
app:tabIndicatorColor="@color/accentColor"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@android:color/black"
app:tabIndicatorHeight="4dp" />
android:id="@+id/benefit_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
layout="@layout/floating_btn_benefits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
/>