It's not a bug; you need to go through the Context/Resource to find the
correct app scaling, and a plain constructor does not have this so can not
take such things into account.

You should define attributes like text sizes in resources, where you can use
units like "dp" and use those values to set your size.  This is essentially
how TextView works, where it gets a style array of the attributes (size,
color, etc) it uses to initialize its paint.

On Wed, Jun 2, 2010 at 8:30 AM, String <[email protected]>wrote:

> I think it is a bug, personally. Paint has a similar problem with
> measureText(); it doesn't account for different screen densities
> correctly.
>
> My solution is similar to Kostya's: I handle it manually using the
> reported density of the display.
>
> String
>
> On Jun 2, 1:38 pm, Kostya Vasilyev <[email protected]> wrote:
> > 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]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
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