1、Width = Wrap_content Height=Wrap_content:
Wrap(
children: <Widget>[your_child])
流式布局,会自动换行
2、Width = Match_parent Height=Match_parent:
Container(
height: double.infinity,
width: double.infinity,child:your_child)
3、Width = match_parent ,Height = wrap_conten:
Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[*your_child*],
);
4、Width = Wrap_content ,Height = Match_parent:
Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[your_child],
);
5、占满剩余空间Expanded
Expanded(child:your_child)
Expanded
为Flexible,默认 flex: 1
,flex
相当于android里的weight
6、主轴平均分配空间MainAxisAlignment.spaceAround
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
your_child1,
your_child2,
your_child3,
],
)
7、Row/Column 常用的属性:
- children → List - 子组件列表
- mainAxisAlignment → MainAxisAlignment - 主轴对齐方式。
- crossAxisAlignment → CrossAxisAlignment - 侧轴对齐方式。
- mainAxisSize → MainAxisSize - 本类的主轴大小。
- textBaseline → TextBaseline - 基线对齐方式。
- textDirection → TextDirection - 水平方向上的组件顺序。
- verticalDirection → VerticalDirection - 垂直方式上的子组件顺序。
Row 有以下特点(Column 也一样): - 它的最大高度是子组件的最大高度。
- Row 的宽度由 mainAxisSize 属性确定。如果 mainAxisSize 属性是 MainAxisSize.max,则 - - Row 的宽度是传入约束的最大宽度。
- 根据 mainAxisAlignment(主轴)和 crossAxisAlignment(侧轴)确定每个子组件的位置。
-
添加 mainAxisSize: MainAxisSize.min 后。
image.png
当设置 mainAxisAlignment: MainAxisAlignment.spaceBetween 的时候。

更具体的布局内容可以参与Flutter布局详解
水平和垂直布局详解
网友评论