17、Flutter Widget - Spacer;

  RowColumn有可以用来均匀分配子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(),
],
)
复制代码

猜你喜欢

转载自blog.csdn.net/weixin_34377919/article/details/91395689