使用GridView將widget放置爲二維列表。 GridView提供了兩個預製list,或者您能夠構建自定義網格。當GridView檢測到其內容太長而不適合渲染框時,它會自動滾動。html
GridView.count
容許您指定列數GridView.extent
容許您指定項的最大像素寬度
案例效果:java
官方文檔(相關屬性)介紹:app
https://docs.flutter.io/flutter/widgets/GridView-class.htmlless
案例代碼:ide
/*** * 列表GridView */ class UITest3_GridView extends StatelessWidget{ List<Container> buildGridList(int count){ return new List<Container>.generate(count, (int index) => new Container( child: new Image.asset("images/lake.jpg"), ) ); } Widget builGrid(){ return new GridView.extent( maxCrossAxisExtent: 150.0, padding: EdgeInsets.all(4), mainAxisSpacing: 4, crossAxisSpacing: 4, children: buildGridList(30) ); } @override Widget build(BuildContext context) { // TODO: implement build return new Scaffold( appBar: AppBar( title: new Text("GridView"), ), body: new Center( child: builGrid(), ), ); } }