flutter Flex Wrap Stack Align布局

1.flex布局:

在这里插入图片描述

Flex(
direction: Axis.horizontal, //水平反向(direction不能为空)
direction: Axis.vertical, //垂直反向
Expanded(
flex: 1
)
)

实现代码如下:

child: Container(
 width: 400,
 height: 150,
 color: Colors.grey,
 child: Flex(
   direction: Axis.horizontal, //水平反向(direction不能为空)
   // direction: Axis.vertical, //垂直反向
   children: <Widget>[
     Expanded( //flex默认=1
       flex: 1,
       child: Container(
         //width: double.infinity //垂直反向使用
         height: 40,
         color: Colors.pink,
         child: Text('aaa'),
       ),
     ),
     Expanded(
       flex: 2,
       child: Container(
         height: 60,
         color: Colors.yellow,
         child: Text('bbb'),
       ),
     ),
     Expanded(
       flex: 3,
       child: Container(
         height: 80,
         color: Colors.blue,
         child: Text('ccc'),
       ),
     ),
   ]
 )
),

2.Wrap 流布局:

在这里插入图片描述

child: Container(
 width: 300,
 height: 200,
 color: Colors.grey,
 child: Wrap(
   spacing: 10, //左右间距
   runSpacing: 10, //下间距
   direction: Axis.vertical, //垂直
   crossAxisAlignment: WrapCrossAlignment.start,
   children: <Widget>[
     Container(
       width: 140,
       height: 80,
       color: Colors.pink,
       child: Text('aaa'),
     ),
     Container(
       width: 140,
       height: 80,
       color: Colors.yellow,
       child: Text('bbb'),
     ),
     Container(
       width: 140,
       height: 80,
       color: Colors.blue,
       child: Text('ccc'),
     ),
   ]
 )
),
),

2.Stack 层叠布局:

在这里插入图片描述

child: Container(
  width: 300,
  height: 200,
  color: Colors.grey,
  child: Stack(
    // alignment: Alignment.center,  //居中
    alignment: AlignmentDirectional.center,
    overflow: Overflow.visible, //超出显示
    children: <Widget>[
      Positioned(
        top: 20,
        left: 20,
        child: Container(
          width: 150,
          height: 150,
          color: Colors.pink,
          child: Text('aa')
        ),
      ),
      Container(
        width: 150,
        height: 150,
        color: Colors.yellow,
        child: Text('bb')
      ),
    ],
  )
),

3. Align布局

在这里插入图片描述

child: Container(
  width: 300,
  height: 200,
  color: Colors.yellow,
  alignment: Alignment.topLeft,
  child: Align(
    widthFactor: 2,
    heightFactor: 2,
    alignment: Alignment.topRight,
    child: FlutterLogo(size: 60,),
  )
),
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值