为何Jetpack Compose中Typography API配置Roboto Flex与GenericFontFamily渲染不同?
Jetpack Compose字体行高差异问题
从示例代码及渲染效果可见,通过Jetpack Compose Typography API直接调用系统Roboto字体(最右侧文本框)时,行高比通过默认Typography(GenericFontFamily/最左侧文本框)配置的Roboto字体要大。
示例代码
Row { MaterialTheme { Column { Box( modifier = Modifier.border( 1.dp, color = Color.Black ) ) { Text( testText, style = MaterialTheme.typography.headlineLarge.copy( // fontSynthesis = FontSynthesis.None ), maxLines = 1, ) } } } MaterialTheme( typography = proximaTypography(), ) { Column { Box( modifier = Modifier.border( 1.dp, color = Color.Black ) ) { Text( testText, style = MaterialTheme.typography.headlineLarge.copy( // fontSynthesis = FontSynthesis.None ), maxLines = 1, ) } } } MaterialTheme( typography = robotoTypography(), ) { Column { Box( modifier = Modifier.border( 1.dp, color = Color.Black ) ) { Text( testText, style = MaterialTheme.typography.headlineLarge.copy( // fontSynthesis = FontSynthesis.None ), maxLines = 1, ) } } } }
默认渲染效果

完整源码可参考dazza5000的fontsforever项目。
优化方案
将includeFontPadding设置为false后,各文本框的渲染效果会更一致:

内容的提问来源于stack exchange,提问作者dazza5000
相关产品推荐
相关产品推荐

