Scale independent pixel pixel

I do not know how it is converted to a unit of pixels. For example, if I assigned 10sp to my font size on a 160 dpi device, how many pixels are my font size? Or, if I assign 10sp to my font on a device with a resolution of 240 dpi, how many pixels are my font size?

+5
source share
2 answers

They are the same as dip, but they also take into account the font scaling factor that the user installs on his device. Therefore, if he / she leaves the font size equal to "normal", it just looks like dip. If there is a font scaling factor, you can get all the scaled density from DisplayMetrics.scaledDensity .

(I have to admit that I just tried to find some “font size” parameter in my global settings of the Android phone, and I couldn’t find it, so I wonder if it can use it now.?)

+7
source

It depends on the screen density set for the device. You can get it with

screenDensity = this.getResources().getDisplayMetrics().density;

, screenDensity dp sp, . , 320x240 creen 0,75, HTC Desire HD Galaxy Tab 1,5, dpi.

0

All Articles