GridView

常用属性:

  • crossAxisSpacing:网格间的空当。
  • crossAxisCount:一行放置的网格数量
body: GridView.count(
            padding: EdgeInsets.all(20.0),
            crossAxisSpacing: 10.0,
            crossAxisCount: 3,
            children: <Widget>[
              const Text('I am j.y.d'),
              const Text('I love flutter'),
              const Text('jyd0124.com'),
              const Text('2020/02/06'),
              const Text('Come on,China!'),
              const Text('Come on,Wuhan!'),
            ],
          ),

官方已经不鼓励使用这种方法,另一种写法为

body: GridView(
           gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
             crossAxisCount: 3,
             mainAxisSpacing: 2.0,
             crossAxisSpacing: 2.0,
             childAspectRatio: 0.75,
             ),
            children: <Widget>[
              new Image.network('http://img5.mtime.cn/mg/2019/10/02/105324.67493314_170X256X4.jpg',fit:BoxFit.cover),
              new Image.network('http://img5.mtime.cn/mg/2019/09/26/092514.83698073_170X256X4.jpg',fit:BoxFit.cover),
              new Image.network('http://img5.mtime.cn/mg/2019/11/07/111316.10093613_170X256X4.jpg',fit:BoxFit.cover),
              new Image.network('http://img5.mtime.cn/mg/2019/12/13/094432.64997517_170X256X4.jpg',fit:BoxFit.cover),
              new Image.network('http://img31.mtime.cn/mt/2014/02/22/230757.74994253_220X124X4.jpg',fit:BoxFit.cover),
              new Image.network('http://img5.mtime.cn/mg/2019/07/10/164947.40820910_170X256X4.jpg',fit:BoxFit.cover),
            ],
        ),
  • childAspectRatio:宽高比
  • mainAxisSpacing:横向网格空档 
  • crossAxisSpacing: 向纵向网格空挡
posted @ 2020-03-13 15:06  lai1322  阅读(109)  评论(0编辑  收藏  举报