Flutter-GridView

Flutter组件之GridView

##创建方式一:

  1. GridView.count(crossAxisCount);
  2. GridView.custom(gridDelegate, childrenDelegate);
  3. GridView.builder(gridDelegate, itemBuilder);
  4. GridView.extent(maxCrossAxisExtent);
GridView.count()

必选

1. children 		=> List<Widget>	组件数组    
2. crossAxisCount	=> int			列数     

可选

1. crossAxisSpacing 	=> double				左右间隔(列间距)默认0.0
2. mainAxisSpacing 		=> double				上下间隔(行间距)默认0.0
3. padding				=> EdgeInsetsGeometry	内间距
4. scrollDirection		=> Axis					滚动方向,默认垂直
5. childAspectRatio		=> double				宽高比,默认1.0

例子

class MyGridView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GridView.count(
      padding: const EdgeInsets.all(5.0),
      crossAxisSpacing: 5.0,
      mainAxisSpacing: 5.0,
      crossAxisCount: 3,
      childAspectRatio: 4/3,
      children: <Widget>[
        new Image.network(imgUrl,fit: BoxFit.cover,),
        new Image.network(imgUrl,fit: BoxFit.cover,),
        new Image.network(imgUrl,fit: BoxFit.cover,),
        new Image.network(imgUrl,fit: BoxFit.cover,),
        new Image.network(imgUrl,fit: BoxFit.cover,),
        new Image.network(imgUrl,fit: BoxFit.cover,),
        new Image.network(imgUrl,fit: BoxFit.cover,),
      ],
    );
  }
}

##创建方式二:

  1. new GridView(gridDelegate,children)
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount

GridView必选

1. children 		=> List<Widget>			组件数组    
2. gridDelegate		=> SliverGridDelegate	表格委托 

GridView可选

1. padding				=> EdgeInsetsGeometry	内间距
2. scrollDirection		=> Axis					滚动方向,默认垂直

SliverGridDelegateWithFixedCrossAxisCount

1. crossAxisCount: 3,    //列数
2. mainAxisSpacing: 2.0, //上下间隔(行间距)
3. crossAxisSpacing: 2.0,//左右间隔(列间距)
4. childAspectRatio: 1.5,//宽高比(宽比高)

例子

class MyGridView1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new GridView(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 3,    
        mainAxisSpacing: 2.0, 
        crossAxisSpacing: 2.0,
        childAspectRatio: 1.5,
      ),
      padding: EdgeInsets.fromLTRB(3.0,10.0,3.0,0.0),
      children: <Widget>[
        new Image.network(imgUrl,fit: BoxFit.cover,),
        new Image.network(imgUrl,fit: BoxFit.cover,),
        new Image.network(imgUrl,fit: BoxFit.cover,),
        new Image.network(imgUrl,fit: BoxFit.cover,),
        new Image.network(imgUrl,fit: BoxFit.cover,),
        new Image.network(imgUrl,fit: BoxFit.cover,),
        new Image.network(imgUrl,fit: BoxFit.cover,),
      ],
    );
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值