【问题标题】:How do set text line height in flutter?如何在颤动中设置文本行高?
【发布时间】:2019-09-29 15:48:07
【问题描述】:

所以在 Onboarding 下的 Material Design Spec 中:here

规定:

32sp 行高

这是从标题文本底部到副标题文本基线的高度。

我的问题是如何在颤振中实现这一点。填充是否足以模仿这个规范?还是有其他更准确的方法来做到这一点?

【问题讨论】:

    标签: flutter material-design


    【解决方案1】:

    是的,TextStyle 中还有一个height 属性,可让您手动调整线条的高度。

    代码片段

    Text('Hey There', 
      style: TextStyle(height: 5, fontSize: 10),
    )
    

    【讨论】:

    • 这是如何计算的?就像上面所说的如何准确地拥有 32sp?
    • 根据我的观察height 没有定义行之间的高度。相反,它定义了文本的可绘制区域的高度。这意味着如果它太小,则字母会被裁剪。
    【解决方案2】:

    除了 Ayush 的回答。如果我们查看documentation,我们可以看到

    When height is non-null, the line height of the span of text will be a multiple of fontSize and be exactly fontSize * height logical pixels tall.

    例如,如果想要高度为 24.0,字体大小为 20.0,我们应该有高度属性 1.2

    例子:

    TextStyle(
          fontSize: 20.0,
          height: 1.2,
    );
    

    【讨论】:

    • 非常感谢,这很有用
    猜你喜欢
    • 2019-04-30
    • 1970-01-01
    • 2023-03-03
    • 2015-07-01
    • 1970-01-01
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    • 2020-05-06
    相关资源
    最近更新 更多