ListView是列表,如何实现横向滚动呢?
import 'package:flutter/material.dart';
void main() {
runApp(new myApp());
}
class myApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'welcome',
home: new Scaffold(
body: Center(
child: new Container(
child: new ListView(
// 配置 scrollDirection 属性实现横向滚动
scrollDirection: Axis.horizontal,
children: <Widget> [
new Container(
height: 200.0,
width: 150.0,
color: Colors.limeAccent
),
new Container(
height: 200.0,
width: 150.0,
color: Colors.greenAccent
),
new Container(
height: 200.0,
width: 150.0,
color: Colors.limeAccent
),
]
),
height: 200.0,
width: 300.0,
color: Colors.blueAccent
),
)
)
);
}
}
ListView 默认是一个列表,但是把它放到一个
Container
容器中可以实现滚动效果,设置Container
属性height
和scrollDirection
来实现滚动效果
scrollDirection
默认有两个值
Axis.horizontal
(横向/水平)Axis.vertical
(纵向/垂直)