最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin6浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论