android layout 工具栏,android - 滚动时CollapsingToolbarLayout并隐藏工具栏 - SO中文参考 - www.soinside.com...

我正在尝试使用CoordinatorLayout和CollapsingToolbarLayout创建一些组合布局。

在第一个状态,当我们在最顶层的页面上,并且还没有滚动时,我希望工具栏如下所示(是的,我做到了):

eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9mZmZrei5wbmcifQ==

在第二种状态下,当开始向下滚动时,图像和工具栏应该消失,如下所示(仅显示选项卡):

eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS85TW9PWC5wbmcifQ==

在最后一个状态中,一旦我在列表中的某个点(但不是列表的顶部),我想开始向上滚动,一旦我开始向上滚动,我想要工具栏(而不是图像中消耗的工具栏)开始哇哇,如下图所示(如果没有到达列表的顶部,图像将不会显示,只有工具栏):

eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9acUV4bC5wbmcifQ==

我能够实现第一个状态,但另一个状态是有问题的,一旦工具栏在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"

/>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值