android - 如何将“SliverPersistentHeader”固定在顶部,直到向下滚动后到达“SliverList”的第一项?
问题描述
我在 CustomScrollView 中使用 SliverPersistentHeader 和 SliverList 。在到达 SliverList 的第一项(索引:0)之前,我不希望我的 SliverPersistentHeader 下降。即使我在 sliverlist 的索引 50,当我向下滚动时,标题仍然会下降。有没有捷径可以做到这一点?
这是我得到的 ==>> https://i.imgur.com/yl48Kx2.gif
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SafeArea(
child: Material(
child: CustomScrollView(
slivers: [
SliverPersistentHeader(
delegate: MySliverAppBar(expandedHeight: 250),
pinned: true,
floating: true,
),
SliverSafeArea(
sliver: SliverAppBar(
pinned: true,
backgroundColor: Color(0xffA2B8A1),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(_, index) => ListTile(
title: Text("Index: $index"),
),
),
)
],
),
),
);
}
}
解决方案
尝试设置pinned
并true
保持floating
为false
. 这是每个人的工作。
Floating:如果用户反转滚动方向,标题是否应立即再次增长。
Pinned:当标题达到其最小尺寸时,是否将其粘贴到视口的开头。
推荐阅读
- download - 从 Jfrog 下载最新更新的工件
- reactjs - 如何从额外的减速器添加案例中更改另一个减速器的状态
- objective-c - 如何在 keyDown 函数中检查删除字符?
- python - 将数字分成 n 等份
- terminal - 如何压缩传输文件以在 Windows 中使用 Putty?
- c# - 如果输入 json 值整数,则在 .NET 核心 API 中请求模型 null
- c++ - 无法在 VS Code for C++ 中设置包含路径
- api - 获取竹子计划列表(在项目中)和最后成功的内部版本号的 api 是什么?
- r - 试图在 R 中“循环”一个函数
- python - 在假新闻检测 ValueError 中:具有多个元素的数组的真值是不明确的。使用 a.any() 或 a.all()