【发布时间】:2019-01-07 11:59:12
【问题描述】:
我想创建一个水平滚动的卡片列表,并在从左或右滑动时使用对齐效果。
每张卡片之间都有一些间距,适合屏幕,如下图所示
除此之外,这些可水平滚动的列表元素应包含在可垂直滚动的列表中。
在flutter docs中的示例之后,我所能实现的只是显示水平滚动卡的列表。
class SnapCarousel extends StatelessWidget {
@override
Widget build(BuildContext context) {
final title = 'Horizontal List';
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Container(
margin: EdgeInsets.symmetric(vertical: 20.0),
height: 200.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
Container(
width: 160.0,
color: Colors.red,
),
Container(
width: 160.0,
color: Colors.blue,
),
Container(
width: 160.0,
color: Colors.green,
),
Container(
width: 160.0,
color: Colors.yellow,
),
Container(
width: 160.0,
color: Colors.orange,
),
],
),
),
),
);
}
}
【问题讨论】:
-
@RémiRousselet 上面的链接部分解决了我的问题,因为我还想将它们放在垂直滚动列表中。垂直滚动列表中的每个组件都是水平滚动的元素集合。
-
没有什么能阻止您使用上一个链接进行操作
-
@RémiRousselet 你能提供一个基本的例子吗?我不知道如何让它垂直滚动。
-
你不能让它垂直滚动。将其包裹在
ListView中
标签: dart flutter flutter-layout flutter-animation flutter-sliver