在Android中,我们可以使用LayoutGravity
将元素放置在线性布局中,我想知道如何在Flutter中实现相同的功能。我在一个列中有小部件,我希望一些小部件位于左侧,一些位于右侧,一些位于左侧。我怎样才能做到这一点?这是我的代码:
return new Container(
margin: const EdgeInsets.only(top: 16.0),
color: Colors.white,
child: new Column(
children: <Widget>[
//the following textfields must be positioned on the right, but they are on the center
new Text("Hair cut",),
new Text("Shampoo",),
//the button is in the center and that is correct
new RaisedButton(
onPressed: ()=>{},
color: Colors.purple,
child: new Text("Book",style: new TextStyle(color: Colors.white),),
)
],
),
);
将crossAxisAlignment
设置为CrossAxisAlignment.end
可将所有内容移至右侧。我尝试在自己的Column
窗口小部件中添加文本字段,并将crossAxisAlignment
设置为end
,但没有任何反应。
答案 0 :(得分:6)
您可以为C:\blah\blub\C:\Users\apearson\Documents\Works.xml
设置通用对齐方式。然后通过将其包装在crossAxisAlignment
小部件中来覆盖特定项目。
Align
如果您不希望列填充宽度,您可能还想将new Column(
children: <Widget>[
//the following textfields must be positioned on the right, but they are not the center
new Align(
alignment: Alignment.centerRight,
child: new Text("Hair cut"),
),
new Align(
alignment: Alignment.centerRight,
child: new Text("Shampoo"),
),
//the button is in the center and that is correct
new RaisedButton(
onPressed: () => {},
color: Colors.purple,
child: new Text(
"Book",
style: new TextStyle(color: Colors.white),
),
)
],
),
打包到Column
。