颤动的位置小部件

时间:2018-05-08 14:15:52

标签: dart flutter

在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,但没有任何反应。

1 个答案:

答案 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