【发布时间】:2020-07-14 10:54:07
【问题描述】:
我正在尝试实现我们在 android WhatsApp 中看到的行为,并建议材料设计中的选项卡行为,查看建议 here 和视频 here。当我向下滚动时,我希望标签栏可见但应用栏隐藏,这种行为也可以在中型 android 应用上看到。
我看到有一个较早的答案here,但它对我不起作用。
我尝试了几种方法,但嵌套滚动视图对我不起作用。
return DefaultTabController(
length: 2,
child:Scaffold(
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
title: Text("Application"),
floating: true,
pinned: true,
snap: true,
bottom: TabBar(
tabs: <Tab>[
Tab(text: "T"),
Tab(text: "B"),
], // <-- total of 2 tabs
),
),
];
},
body: TabBarView(
children: <Widget>[
RandomWords(),
RandomWords(),
],
),
),
),
);
也试过了,
Scaffold(
body: NestedScrollView(
controller: _scrollViewController,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
title: Text("N"),
pinned: true,
floating: true,
forceElevated: innerBoxIsScrolled,
//snap: true,
bottom: TabBar(
tabs: <Tab>[
Tab(text: "T"),
Tab(text: "B"),
],
controller: _tabController,
),
)
];
},
body: TabBarView(
children: <Widget>[
RandomWords(),
RandomWords(),
],
controller: _tabController,
),
),
),
);
我的代码可用here。
NestedScrollView 是否有任何原因可能不起作用?
【问题讨论】:
-
您可以添加您尝试过的代码吗?