react native - Text line height is incorrect in Android - Stack Overflow

I set the line height of the text to 20 but when I render the text and try to get the line height from

I set the line height of the text to 20 but when I render the text and try to get the line height from onTextLayout it find it equal to 20.190475463867188 (it changes depending on the device) .. is this the expected behavior? in iOS the line is exactly equal to 20.

This is the snack demo: /@abdel.moun/text-line-height

I set the line height of the text to 20 but when I render the text and try to get the line height from onTextLayout it find it equal to 20.190475463867188 (it changes depending on the device) .. is this the expected behavior? in iOS the line is exactly equal to 20.

This is the snack demo: https://snack.expo.dev/@abdel.moun/text-line-height

Share Improve this question asked Mar 21 at 18:20 lawaybenlawayben 712 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

When you set line height to 20 but get 20.190475463867188 on Android (while iOS returns exactly 20), this is normal behavior due to fundamental platform differences:

iOS preserves exact line height values, while Android applies additional font metrics adjustments based on the device's density scaling factor. Android converts your specified values into device-independent pixels (dp) to maintain consistent text appearance across varied screen densities including but not limited to the foldable phones, watches, tablets. This slight variance won't affect visual consistency and requires no correction on your end. You can read more about Pixel Density on Android on the Material Design website.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744339808a4569335.html

相关推荐

  • react native - Text line height is incorrect in Android - Stack Overflow

    I set the line height of the text to 20 but when I render the text and try to get the line height from

    9天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信