admin管理员组

文章数量:1402407

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.

本文标签: react nativeText line height is incorrect in AndroidStack Overflow