作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在屏幕底部的一行中有两个按钮。我想将第一个按钮保留在中心,将第二个按钮保留在最后。我怎样才能做到这一点?
这是我的代码
new Container
(
child:Row(
children:<Widget>[
new RaisedButton(
color: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
onPressed: takescrshot,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Next',
style:
TextStyle(fontSize: 23, color: Colors.white),
),
),
),
new FloatingActionButton.extended(
onPressed: () {
// Add your onPressed code here!
},
label: Text('options'),
icon: Icon(Icons.menu),
backgroundColor: Colors.pink,
),
])
)
谁能指导我?
最佳答案
您需要了解 Column
和 Row
努力定位它的 child 以及如何正确使用Flexible
小部件使每个子位置都随心所欲。
您有一个 Row
那里有两个按钮作为子项(一个 RaisedButton
和一个 FloatingActionButton
),但它们不限于任何位置,因此它们都放在 Row
的开头在左侧对齐。
Expanded
包裹每个按钮。 .Center
包裹每个按钮。所以它们在每个 Expanded
的空间内居中.如果没有,请跳过此步骤。现在看起来好多了,对吧?const Spacer()
作为 Row
的第一个 child 所以它实际上与所有其他 2 个 sibling 共享“不可见”空间;Container(
child: Row(
children: <Widget>[
const Spacer(),
Expanded(
child: Center(
child: RaisedButton(
color: Colors.red,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
onPressed: takescrshot,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Next',
style: TextStyle(fontSize: 23, color: Colors.white),
),
),
),
),
),
Expanded(
child: Center(
child: FloatingActionButton.extended(
onPressed: () {
// Add your onPressed code here!
},
label: Text('options'),
icon: Icon(Icons.menu),
backgroundColor: Colors.pink,
),
),
),
],
));
关于Flutter-如何在一行中的特定位置对齐按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62995701/
我是一名优秀的程序员,十分优秀!