android - 容器包装了文本小部件,但为什么按钮小部件会受到 textAlign 的影响?
问题描述
先生,在代码中我包装了唯一的 Text 小部件。之后,我使用了一些自定义样式,例如文本对齐。但是在使用之后,我希望只将文本部分居中,因为只有这个小部件不会被包裹到另一个小部件上。但我看到我的按钮也居中。怎么可能?我被包裹了一个小部件,但我的另一个小部件受到影响。先生,这里面有什么逻辑?
解决方案
您需要设置一个crossAxisAlignment: CrossAxisAlignment.start
, 并用中心小部件包装标题文本。希望下面的代码可以给你一个很好的例子。
class Demo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("title"),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Center(
child: Text("Whats your favourite food?"),
),
RaisedButton(
onPressed: () {},
child: Container(
padding: EdgeInsets.zero,
decoration: BoxDecoration(),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Answer 1"),
),
),
),
RaisedButton(
onPressed: () {},
child: Container(
padding: EdgeInsets.zero,
decoration: BoxDecoration(),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Answer 1"),
),
),
),
RaisedButton(
onPressed: () {},
child: Container(
padding: EdgeInsets.zero,
decoration: BoxDecoration(),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Answer 1"),
),
),
),
],
),
);
}
}
推荐阅读
- javascript - Javascript - 如何从我用来查询数据库的承诺中将变量发送到我的前端?
- python - 导入 python-pptx: ModuleNotFoundError: No module named 'pptx'
- javascript - 如何在 JAVASCRIPT 中对原始 PDF 内容(字节)进行 base64 编码?
- r - 有效地从一个数据帧中查找另一个数据帧中的数据。
- javascript - 如何查看为什么在 npm 中安装了依赖项?
- rabbitmq - RabbitMQ - 发布到主题交换的消息 - 消费者未按相同顺序接收
- algorithm - 最短路径距离 -> 如何处理负权重?
- ios - 滚动视图内的pageviewcontroller内的iOS tableview
- azure-sql-database - 从 DB Azure 查询到本地数据库
- javascript - 循环使用 Firestore 查询 [Web/Javascript]