【发布时间】:2019-10-20 00:14:05
【问题描述】:
如何使Rows 在垂直ListView 内,可水平滚动。
这就是我的应用的样子:
我希望用户能够水平滚动 ListView(以查看 Row 的内容)和垂直滚动以查看新列表项。这种行为就像在 Flutter 中滚动 DataTable:
这里是构建方法(基于Flutter项目模板):
@override
Widget build(BuildContext context) {
final List<String> rows = [
"This is a row with some very long text ... That goes on and on",
"This class is the configuration for the state.",
"case the title) provided by the parent (in this case the App widget) and",
"always marked \"final\"."
];
return Scaffold(
appBar: AppBar(title: Text("ListView")),
body: ListView(
padding: EdgeInsets.all(10),
children: <Widget>[
for (final String row in rows)
Row(
children: <Widget>[Text(row)],
)
],
),
);
}
更新:将 Text 包裹在 Expanded 中不起作用,因为它会导致文本换行成多行。我希望文本保留在一行上。
【问题讨论】:
-
添加一个列表视图作为子视图并使用 scrollDirection: Axis.horizontal 。
-
@Rubens Melo 那只会让单行滚动,但是有没有办法让整个 ListView 滚动?