Eric,

I ran into same issues with my app.

First of all, small text can be made more readable by calling paint.setAntiAlias(true);

Second, I do my own text scaling based on the device's screen density. Something like: textSize = unscaledSize * screenDensity / 160.0f. Note that default density for pre-1.6 devices is 160 dpi.

Screen density is available as canvas.getDensity(), which first appeared in API 4 (Android 1.6).

Since I want my app run on Android 1.5, I wrote a simple helper method using Java reflection that works on all versions of Android.

public static int getScreenDensity(Canvas canvas) {
if (gScreenDensity == 0) {
gScreenDensity = 160;

Class<? extends Object> canvasClass = canvas.getClass();
try {
Method getDensityMethod = canvasClass.getMethod("getDensity");
gScreenDensity = (Integer) getDensityMethod.invoke(canvas);
} catch (NoSuchMethodException x) {
} catch (InvocationTargetException x) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
}
}

return gScreenDensity;
}

static int gScreenDensity = 0;

Hope this helps.

02.06.2010 16:24, eehouse пишет:
My app uses a custom View that does a lot of text drawing.  To ensure
my text is always readable I've been using the result of calling
getTextSize() on a newly-created Paint() instance as the minimum
size.  Docs say calling 'new Paint()' sets attributes like text size
to default values.

One of my European users just got a Motorola Milestone phone and
reports that some text is unreadably small.  I believe I've duplicated
this using the WVGA854 skin in a 2.1 emulator.  Run in that emulator
my app's smallest TextViews look fine, but the text I'm drawing myself
using Paint instances where I haven't changed the text size from the
default is too small.  I confirmed this by commenting out all
setTextSize() calls in my View subclass: the text becomes too small to
read comfortably.

It feels like a bug to me that the default text size on Paint can be
significantly smaller than default TextView size on some devices.  Is
it a known bug?

In the meantime, can someone suggest a way to size Paint text so that
it's readable on any device regardless of screen resolution?  I
believe there are APIs to translate inches to pixels, so perhaps I
could hard-code a size in inches.  Or I could measure the laid-out
height of a TextView and store that as an invisible preference.  But
is there a better way, say an API I haven't found?  (I suspect it'd be
enough if Paint were like TextView in allowing you to specify the
units in which text size is set, but it doesn't.)

Thanks,

--Eric



--
Kostya Vasilev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to