如何移除Android Jetpack Compose中Text组件的默认垂直内边距?
移除Jetpack Compose Text组件垂直内边距的问题
如您所见,Text组件存在垂直内边距:
我尝试了两种方法移除这个垂直内边距,但均未生效:
Text( text = "2", fontSize = 100.sp, // ================== // Case 1. modifier = Modifier.padding(0.dp), // 首先尝试的方法,无效。 // ================== // Case 2. style = LocalTextStyle.current.merge( // 第二种方法,同样无效。 TextStyle( fontSize = 100.sp, // lineHeight = 2.5.em, lineHeightStyle = LineHeightStyle( alignment = LineHeightStyle.Alignment.Bottom, trim = LineHeightStyle.Trim.LastLineBottom, ), ), ) ) // Text() 结束
我希望彻底移除Text组件的内边距,实现内边距为0的效果。
补充测试
我还在@Preview函数中做了测试:
@Preview @Composable fun PreviewText100sp() { Text( "100", fontSize = 100.sp ) }
但预览中的Text仍然存在垂直内边距:
内容的提问来源于stack exchange,提问作者Steve
相关产品推荐
相关产品推荐

