Flutter中GridView使用

常用GridView.count:

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: AppBar(
        title: Text('我是首页'),
      ),
      body: new SafeArea(
        child: new GridView.count(
          primary: false,
          scrollDirection: Axis.vertical,
          crossAxisCount: 2, // 横向item个数
          padding: const EdgeInsets.all(5.0), // 内边距
          crossAxisSpacing: 10.0, // 横向间距
          mainAxisSpacing: 10.0, // 竖向间距
          children: <Widget>[
            new Image.asset('images/11.png', fit: BoxFit.fill,),
            new Image.asset('images/22.png', fit: BoxFit.fill,),
            new Image.asset('images/22.png', fit: BoxFit.fill,),
            new Image.asset('images/11.png', fit: BoxFit.fill,),
            new Image.asset('images/22.png', fit: BoxFit.fill,),
            new Image.asset('images/11.png', fit: BoxFit.fill,),
            new Image.asset('images/11.png', fit: BoxFit.fill,),
            new Image.asset('images/22.png', fit: BoxFit.fill,),
            new Image.asset('images/11.png', fit: BoxFit.fill,),
            new Image.asset('images/22.png', fit: BoxFit.fill,),
            new Image.asset('images/22.png', fit: BoxFit.fill,),
            new Image.asset('images/11.png', fit: BoxFit.fill,),
            new Image.asset('images/22.png', fit: BoxFit.fill,),
            new Image.asset('images/11.png', fit: BoxFit.fill,),
            new Image.asset('images/11.png', fit: BoxFit.fill,),
            new Image.asset('images/22.png', fit: BoxFit.fill,),
          ],
        ),
      ),
    );
  }
}

竖屏:


2988687-d3a0ee434a659373.png
Simulator Screen Shot - iPhone XS - 2019-01-24 at 14.16.12.png

横屏:


2988687-005a1a710016c403.png
Simulator Screen Shot - iPhone XS - 2019-01-24 at 14.16.19.png

猜你喜欢

转载自blog.csdn.net/weixin_34208185/article/details/86785069