Flutter实现网格布局1

上一次有人在问是否可以用Grid布局,可以。
上一次的做法:
链接: link.
效果图:
在这里插入图片描述
提示一下部分代码的意思;
在这里插入图片描述
实现方式:GridView.count
实现代码如下:

import 'package:flutter/material.dart';

class GridPage extends StatelessWidget {
  Widget centreSection() {
    return Container(
      height: 300,
      child: GridView(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 3, //每一行的列数
          mainAxisSpacing: 10, //主轴方向上的间距
          crossAxisSpacing: 10, //交叉轴轴方向上的间距
          childAspectRatio: 1.2, //子元素的宽高比例
        ),
        children: [
          Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage('images/beauty1.png'),
              ),
            ),
            child: Text(
              "美少女1号",
            ),
            alignment: Alignment.bottomCenter,
          ),
          Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage('images/beauty1.png'),
              ),
            ),
            child: Text(
              "美少女1号",
            ),
            alignment: Alignment.bottomCenter,
          ),
          Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage('images/beauty1.png'),
              ),
            ),
            child: Text(
              "美少女1号",
            ),
            alignment: Alignment.bottomCenter,
          ),
          Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage('images/beauty2.png'),
              ),
            ),
            child: Text(
              "美少女2号",
            ),
            alignment: Alignment.bottomCenter,
          ),
          Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage('images/beauty2.png'),
              ),
            ),
            child: Text(
              "美少女2号",
            ),
            alignment: Alignment.bottomCenter,
          ),
          Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage('images/beauty2.png'),
              ),
            ),
            child: Text(
              "美少女2号",
            ),
            alignment: Alignment.bottomCenter,
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("甜宠软妹"),
        centerTitle: true,
      ),
      body: Container(padding: EdgeInsets.all(10.0), child: centreSection()),
    );
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值