颤振将两个项目在极端位置对齐-一项在左侧,另一项在右侧 [英] Flutter align two items on extremes - one on the left and one on the right
本文介绍了颤振将两个项目在极端位置对齐-一项在左侧,另一项在右侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将两个项目的极端对齐,一个在左边,另一个在右边. 我有一排在左边对齐,然后该行的一个孩子在右边对齐.但是,似乎子行正在从其父行中获取alignment属性.这是我的代码
I am trying to align two items at extremes one on the left and one on the right. I have one row that is aligned to the left and then a child of that row is aligned to the right. However it seems the child row is picking up the alignment property from its parent. This is my code
var SettingsRow = new Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Text("Right",softWrap: true,),
],
);
var nameRow = new Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Text("Left"),
SettingsRow,
],
);
结果我得到了类似的东西
as a result I get something like this
Left Right
我想要的是
Left Right
行上也有足够的空间.我的问题是为什么子Row不能显示其MainAxisAlignment.end
属性?
Also there is enough space on the Row. My question is why is the child Row not exhibiting its MainAxisAlignment.end
property ?
推荐答案
使用单个Row
代替mainAxisAlignment: MainAxisAlignment.spaceBetween
.
new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
new Text("left"),
new Text("right")
]
);
或者您可以使用Expanded
new Row(
children: [
new Text("left"),
new Expanded(
child: settingsRow,
),
],
);
这篇关于颤振将两个项目在极端位置对齐-一项在左侧,另一项在右侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文