我有一个似乎无法解决的难题。我在Flutter中已有一排。本质上,我想完成的是在行的开头放置第一个元素(黄色),在元素的中心放置第二个元素(红色)。我知道Row具有mainAxisAlignment
,但是每个元素(即MainAxisAlignment.start
&MainAxisAlignment.center
)都需要不同的对齐方式。谢谢你的帮助!
我能够得出的最接近的结果是:
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
yellowElement,
Expanded(child: redElement),
],
);
但这并不是完全居中,而是在黄色占据空间后剩余的可用空间中居中。
几周前我遇到了这个问题,我发现的唯一解决方案是Stack ...像这样
Stack(
children: <Widget>[
Container(
color: Colors.grey,
width: 250,
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Container(width: 50, color: Colors.red),
],
),
),
Positioned(
top: 0,
bottom: 0,
child: Container(
width: 20,
color: Colors.yellow,
),
)
],
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句