flutter - 多行文本与行高垂直居中对齐
问题描述
我目前正在尝试让文本以特定的行高应用并将文本垂直居中对齐。由于 TextStyle 上没有垂直对齐的选项,因此我尝试使用 StrutStyle 来将其大致对齐到中心。但是,设置前导后,前导的高度和带有TextStyle 高度的Text 的高度是不同的。
该演示可以在dartpad上查看。
Text(
'label A',
style: const TextStyle(
fontSize: 16.0,
color: Colors.red,
backgroundColor: Colors.blue,
),
strutStyle: StrutStyle(
fontSize: 16.0,
leading: (70.0 / 16.0)/2,
forceStrutHeight: true,
),
),
- 想问是否有任何适当的方法将其对准中心?文本是多行的。
- 如果现在这种情况下推荐使用领先的方法,是否有任何计算可以使用领先同步正确的高度?
解决方案
Wrap With Align
Widget 这将帮助您在任何地方对齐。
Align (
alignment : Alignment.topCenter;
child : Text(
'label A',
style: const TextStyle(
fontSize: 16.0,
color: Colors.red,
backgroundColor: Colors.blue,
),
strutStyle: StrutStyle(
fontSize: 16.0,
leading: (70.0 / 16.0)/2,
forceStrutHeight: true,
),
),
),
推荐阅读
- javascript - 如何在 _app.js 中使用 getStaticProps 在 Next.js 的每个页面中显示从 api 获取的数据
- c# - 如何修复呈现一致微小差异的 int 到 hex 转换?
- html - CSS渐变动画出现静止
- ios - xCode 既不接受开发证书也不接受分发
- python - 如何提取文档中具有特定结构的 MONGODB 集合的前 N 个元素
- python - 如何限制python进程的CPU周期和内存
- amazon-web-services - AWS SQS 如何重置消息的 ReceiveCount
- sas - SQL中的if first.row怎么办
- d3.js - 根据 id 检查节点和它的所有子节点
- java - 无法使用 Jolt (V0.1.1) 将 Json 数组转换为 Flattern Json