I have an Android App that dynamically scales text depending on the resolution of the android device. I have tested this code on all the predefined resolutions in the Android Simulator and my code works fine. (This includes the same resolutions as on HTC Desire and Motorola Droid)
It also works fine on my HTC Wildfire.
Here are some screen shots from the simulators:
However... I have tried this on HTC Desire, and I have had reports from users using Motorola Droid that the fonts are not scaling correctly:
Note how it is chopping the text off.
Any ideas why this is not working on these particular devices?
I currently have a function that scales the text down depending on the available height for the text... something like this:
public static float calculateHeight(FontMetrics fm) {
return Math.abs(fm.ascent) + fm.descent;
}
public static int determineTextSize(Typeface font, float allowableHeight) {
Paint p = new Paint();
p.setTypeface(font);
int size = (int) allowableHeight;
p.setTextSize(size);
float currentHeight = calculateHeight(p.getFontMetrics());
while (size!=0 && (currentHeight) > allowableHeight) {
p.setTextSize(size--);
currentHeight = calculateHeight(p.getFontMetrics());
}
if (size==0) {
System.out.print("Using Allowable Height!!");
return (int) allowableHeight;
}
System.out.print("Using size " + size);
return size;
}
Any ideas why this is happening on only a couple of devices? and how I can fix it? Is there another font metric than I need to be considering here which I don't know about? Like Scale or DPI?
Thanks.