我有一个布局喜欢附加的图像。我希望有在相同的屏幕和水平列表视图与流行的/最新的项目和下面的项目的完整列表的GridView。
该ListView应该有水平滚动,而且,所有的屏幕都可以垂直滚动。右边的深色条模拟了滚动条(不是必需的,只是为了说明)。
你可以在Google Play应用程序本身中看到这种行为,在该应用程序中,你可以水平滑动以查看某个类别中的更多项目,也可以垂直滚动以查看更多类别列表。
我尝试过Stack和Column窗口小部件,但都不起作用。对如何构建这个布局有什么想法吗?
发布于 2019-03-25 13:48:11
你可以使用Slivers
,试试我做的这个例子:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(),
body: CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: SizedBox(
height: 100,
child: ListView.builder(
itemExtent: 150,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => Container(
margin: EdgeInsets.all(5.0),
color: Colors.orangeAccent,
),
itemCount: 20),
),
),
SliverGrid(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 1.5,
),
delegate: SliverChildBuilderDelegate(
(context, index) => Container(
margin: EdgeInsets.all(5.0),
color: Colors.yellow,
),
),
)
],
));
}
此外,您还可以通过以下链接了解更多关于Sliver的信息:https://medium.com/flutter-io/slivers-demystified-6ff68ab0296f
https://stackoverflow.com/questions/55331730
复制相似问题