设置子控件间距
- 使用SizedBox保持固定间距
- Row(
- children: <Widget>[
- Text("1"),
- SizedBox(width: 50), // 50宽度
- Text("2"),
- ],
- )
![](https://img-blog.csdnimg.cn/img_convert/eda045aaed269be812510f22ff313740.png)
image.png
- 使用Spacer填充尽可能大的空间
- Row(
- children: <Widget>[
- Text("1"),
- Spacer(), // use Spacer
- Text("2"),
- ],
- )
![](https://img-blog.csdnimg.cn/img_convert/f633158e67cd4d33b50ce2c419775413.png)
image.png
- 使用mainAxisAlignment对齐方式控制彼此间距
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly, //元素与空白互相间隔
- children: <Widget>[
- Text("1"),
- Text("2"),
- ],
- )
![](https://img-blog.csdnimg.cn/img_convert/2ccfbc7084db2a4f8f3e8e96eaf01d10.png)
image.png
- 如果不用行的话,还可以使用Wrap并指定spacing
- Wrap(
- spacing: 100, // set spacing here
- children: <Widget>[
- Text("1"),
- Text("2"),
- ],
- )
![](https://img-blog.csdnimg.cn/img_convert/92b944c5f1afc98c780db7806ca6839c.png)
image.png
- 同样是使用Wrap,设置spaceAround
- Wrap(
- alignment: WrapAlignment.spaceAround, // 空白包围住元素
- children: <Widget>[
- Text("1"),
- Text("2"),
- ],
- )
![](https://img-blog.csdnimg.cn/img_convert/bbb597937561f79f7ab803d9166ef37e.png)
image.png
设置子控件分别左对齐和右对齐
- 使用spaceBetween对齐方式
- new Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- new Text("left"),
- new Text("right")
- ]
- );
- 中间使用Expanded自动扩展
- Row(
- children: <Widget>[
- FlutterLogo(),//左对齐
- Expanded(child: SizedBox()),//自动扩展挤压
- FlutterLogo(),//右对齐
- ],
- );
- 使用Spacer自动填充
- Row(
- children: <Widget>[
- FlutterLogo(),
- Spacer(),
- FlutterLogo(),
- ],
- );
- 使用Flexible
- Row(
- children: <Widget>[
- FlutterLogo(),
- Flexible(fit: FlexFit.tight, child: SizedBox()),
- FlutterLogo(),
- ],
- );
![](https://img-blog.csdnimg.cn/img_convert/9a6a22a2f7913b4bca96396144622132.png)
image.png