简体   繁体   English

如何使用 Android Jetpack Compose Text() 设置行距?

[英]How to set line-space with Android Jetpack Compose Text()?

I want to give more space dp between lines in the Text() content.我想在Text()内容的行之间留出更多的空间dp The only property I find is the letterSpacing of TextStyle , however, it doesn't seem as I want, can we set it with composing somehow?我找到的唯一属性是TextStyleletterSpacing ,但是,它似乎不是我想要的,我们可以以某种方式设置它吗?

With 1.0.0 you can use the lineHeight property:1.0.0您可以使用lineHeight属性:

Text(text = "Hello Compose".repeat(50),
    modifier = Modifier.padding(10.dp).width(200.dp),
    maxLines = 5,
    lineHeight = 50.sp
)

With 20.sp and 50.sp 20.sp50.sp

在此处输入图片说明 在此处输入图片说明

or you can use the TextStyle :或者您可以使用TextStyle

Text(text = "Hello Compose".repeat(50),
    modifier = Modifier.padding(10.dp).width(200.dp),
    maxLines = 5,
    style = LocalTextStyle.current.copy(lineHeight = 50.sp)
)

嗨,尝试更改 TextView 的样式属性 - TextStyle.lineHeight

I did it like this.我是这样做的。

 Text(text = "Hello",
        style = MaterialTheme.typography.h5.copy(
            lineHeight = 35.sp,  // Here line height 
        ),
  )

Or simply you can use lineHeight或者干脆你可以使用 lineHeight

   Text(text = "Hello",
            lineHeight = 35.sp
      )

Caution: sp is case sensitive注意:sp 区分大小写

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM