在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),),
)
],
),
);
Run Code Online (Sandbox Code Playgroud)
设置crossAxisAlignment于CrossAxisAlignment.end一切向右移动.我尝试在自己的Column小部件中添加文本字段并设置crossAxisAlignment为end但没有任何反应.
您可以设置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),
),
)
],
),
Run Code Online (Sandbox Code Playgroud)
如果您不希望列填充宽度,您可能还想将自己包装Column成a IntrinsicWidth.
| 归档时间: |
|
| 查看次数: |
5427 次 |
| 最近记录: |