dart - 颤振位置小部件
问题描述
在 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
但没有任何反应。
解决方案
您可以设置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
成 a 。IntrinsicWidth
推荐阅读
- javascript - vanilla javascript使用链接的点击但不同的命令
- javascript - 触发日期更改时未触发 ng-change 事件
- java - 如何在 Spring Boot 中捕获客户端参数错误的“请求处理失败”?
- mysql - 续集加载初始数据
- outlook - Outlook 加载项的“额外费用披露”失败
- docker - 为什么`oom-kill-disable`对`kubectl create pod`无效,但对自己系统中的`docker run container`有效?
- c# - 如何在 asp.net mvc 中使用引导程序验证您的表单?
- javascript - 不在js中填充字符串值
- php - 如何按时间有效地生成随机唯一临时文件名以存储在自定义目录中?
- angular - 延迟加载打开模式 [Ionic 5]