【问题标题】:How to set Flutter Text line space?如何设置 Flutter Text 行距?
【发布时间】:2019-03-18 06:04:03
【问题描述】:

我以前用Android开发app,现在用Flutter,但是想找和android:includeFontPaddingandroid:lineSpacingExtra一样的Text属性?

【问题讨论】:

    标签: flutter


    【解决方案1】:

    您似乎正在寻找 TextStyle 类的 height 属性。 这是一个例子:

    Text(
      "Some lines of text",
      style: TextStyle(
        fontSize: 14.0,
        height: 1.5 //You can set your custom height here
      )
    )
    

    【讨论】:

    • 它可以工作,但我发现第一行顶部也有空格,flutter 现在的属性与“android:includeFontPadding”相同
    • @andrew 你有没有找到删除这个“字体填充”的方法?
    【解决方案2】:

    您可以设置 2 个属性

    Text("Hello World", style: TextStyle(
      height: 1.2 // the height between text, default is null
      letterSpacing: 1.0 // the white space between letter, default is 0.0
    ));
    

    【讨论】:

    • 现在(Flutter 1.9.1),height: nullheight: 1.0 的行为不同。默认是height: null 而不是height: 1.0
    • @Terry 知道字符间距吗?
    • @Soumen that's letterSpacing
    • @Mariano Zorrilla 是的,我也想要字符间距。有什么想法吗?
    • @YuyaMatsuo 你是对的,实际的height 取决于文本的fontFamily。对于 OpenSans 和 Lato,它似乎是 120%(相当于 Flutter 中的 height: 1.2)。更多详情this Flutter github issue
    猜你喜欢
    • 1970-01-01
    • 2021-09-20
    • 2018-10-15
    • 2021-10-05
    • 2020-10-24
    • 2011-04-20
    • 2013-08-14
    • 1970-01-01
    • 2011-04-22
    相关资源
    最近更新 更多