you should use sp
block for font sizes instead of dip
or dp
. sp
- scale-independent pixels that adjust to fit the pixel density of the screen. here is the exact difference.
dp
Density-independent pixels are an abstract block based on the physical density of the screen. These units refer to a screen with a resolution of 160 dpi, so one pixel is one pixel on a screen with a resolution of 160 dpi. The dp-to-pixel ratio will vary with screen density, but not necessarily in direct proportion. Note. The compiler accepts both "dip" and "dp", although "dp" more closely matches "sp".
sp
Scalable pixels - this is similar to the dp block, but it also scales according to the user's font size preference. It is recommended to use this machine when setting font sizes, so they will be configured both for screen density and user preferences.
source share