我知道他们之间的区别。我要计算文本height
基于 lineHeight
. lineHeight
的值在 TextUnit
所以我想把它转换成Dp
.
最佳答案
您需要获取当前Density
来自 LocalDensity
——所以这只会在合成中起作用,在 @Composable
中函数——并使用它转换为 Dp
:
val lineHeightSp: TextUnit = 12.sp
val lineHeightDp: Dp = with(LocalDensity.current) {
lineHeightSp.toDp()
}
关于android - 如何在 Jetpack Compose 中将 TextUnit 转换为 Dp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65893939/