Search code examples
androidtextfontssizepoints

Physical size of font in points in Android


I have two devices - HTC Tattoo and Sony Ericsson Xperia X10. One has 145 DPI, the other 245 DPI.

When I specify font size for a TextView in points, like this:

textView.setTextSize(TypedValue.COMPLEX_UNIT_PT, 6.5f);

I get different physical size of text on these two devices. On 245 DPI, the text is barely readable.

Now, "pt" size is supposed to be physical. I.e., in my test, both text blocks should have letters of the same physical height. Which is not the case.

What can be wrong here?

Thanks for the help, Yuri.


Solution

  • Actually, points always work whenever the underlying devices gives correct display metrics.

    For example, I tested five devices:

    NAME      OS    metrics.ydpi  REAL_DPI  DDPI  SD
    XPERIA    1.6   159.49677     325       240   1.5
    Liquid    1.6   263.8958      285       240   1.5
    Tattoo    1.6   145.14067     match     120   0.75
    Hero      1.5   179.29352     match     -     1.0
    Galaxy    1.6   160.41878     180       160   1.0
    

    As can be seen, only HTC Tattoo and HTC Hero give proper display info to Android API.

    This is why points have different physical sizes on different devices (not all, though).

    The only way I found to roughly scale fonts / images is to assume everything is 160 DPI and use DisplayMetrics#scaledDensity - which is wrong, but I don't see any other way.