android顶部折叠组件,android – 如何在AppBar折叠/展开时将工具栏固定在顶部?

概观

我正在尝试实现材料设计中描述的具有重叠内容的Scrolling Techniques灵活空间之一.

Flexible space with overlapping content

Content can overlap the app bar.

Behavior:

The app bar’s starting position should be located behind the content.

Upon upward scroll, the app bar should scroll faster than the content,

until the content no longer overlaps it. Once anchored in place, the

app bar lifts up to allow content to scroll underneath.

07001

问题

但问题是,

我的AppBar中的标题在展开时向下滚动并隐藏在重叠内容下方.

在这里,我的工具栏隐藏在重叠的CardView下方.

943723990bd5c2bff716d1a7a1237b1c.png

折叠appbar时,工具栏以及标题从下方向上滑动.

5596ebd43ea1763b49144b6c40178658.png

这是我的代码:

活动的main.xml中

...

android:layout_width="match_parent"

android:layout_height="match_parent">

android:layout_width="match_parent"

android:layout_height="200dp"

android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

...

android:layout_width="match_parent"

android:layout_height="match_parent"

app:layout_scrollFlags="scroll|exitUntilCollapsed">

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"

android:layout_gravity="top"

android:background="?attr/colorPrimary"

app:layout_collapseMode="pin"

app:popupTheme="@style/ThemeOverlay.AppCompat.Light"

app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

android:layout_width="match_parent"

android:layout_height="match_parent"

...

我还在MainActivity的onCreate函数中添加了这些

setSupportActionBar(toolbar);

collapsingToolbarLayout.setTitle("App Name");

我希望工具栏(包含瓷砖和其他内容,稍后我将添加)保持在顶部,而不管appbar是否被展开或折叠.

我已经阅读了这些文档,经历了很多帖子和教程,观看了很多视频但却未能找到可行的解决方案或任何相关的解决方案.

如果有人对如何解决这个问题有所了解,请建议.谢谢你的帮助.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值