Row
和Column
有可以用来均匀分配子Widget
的属性mainAxisAlignment
。
Row(
mainAxisAlignment:MainAxisAlignment.spaceAround,
children:[
MyBox(),
MyBox(),
MyBox()
],
)
复制代码
如果你想更个性化的实现子Widget
的空间分配,可以使用Spacer
;
Row (
children:[
MyBox(),
Spacer(),
MyBox(),
Spacer(),
MyBox(),
],
)
复制代码
只需要添加Spacer
实例到其他Widget
之间,他们就会扩大并建立额外的空间。可以使用默认为 1的flex
属性来定制其相对的尺寸:
Row (
children:[
MyBox(),
Spacer(),
MyBox(),
Spacer(flex:3),
MyBox(),
],
)
复制代码