views:

46

answers:

1

I create a game board with squares. The size of each square (both height and width) is phone_pixel_width/number_of_squares to maximize the size of each square on the game screen depending on resolution (oh and I do not support mdpi devices, thus it does not get to small).

Now my problem is that I also write text in these squares. If I use the same font size for HVGA screens and for WVGA (hdpi-normal) screens the font gets to big on the HVGA (mdpi-normal) screen. I was thinking about being able to select font size depending on its width and could thus adapt the font size perfectly to the calculated square width.

Is there any easy way of doing this (note: I am using TextPaint and not TextView) or do I have to calculate this myself, on the fly so to speak by creating some kind of table at start-up.

Thank you :-)

/ Henrik

+1  A: 

When working with multiple densities, all pixels values should be multiplied by the screen density.

float fontSize = 13 * context.getResources().getDisplayMetrics().density;

density is 1 on mdpi devices and 1.5 on hdpi usually. ldpi is lower.

Moncader