Have you tried scaling using DisplayMetrics.density instead?  The
online docs specifically mentions:

"This value does not exactly follow the real screen size as given by
xdpi and ydpi, but rather is used to scale the size of the overall UI
in steps based on gross changes in the display dpi."

On May 12, 9:41 am, Ab <abe.oppenh...@gmail.com> wrote:
> *Edit.  Sorry, first sentence after "1." should read:
>
> IT seems that the fact that 66 pixels shows on my Galaxy as 8mm,
> when it should be 10mm (based on provided dpi), ISN'T DUE to a false
> dpi
> returned from DisplayMetrics.
>
> On May 12, 12:29 pm, Ab <abe.oppenh...@gmail.com> wrote:
>
> > Diane,
>
> > Thank you for your reply.  I have 2 quick follow up questions:
>
> > 1. I seems that the fact that 66 pixels shows on my Galaxy as 8mm,
> > when it should be 10mm (based on provided dpi), is do to a false dpi
> > returned from DisplayMetrics.  The Galaxy screen measures 3.5 inches
> > wide, and the specs that its resolution is 1024 x 600.  So, 600/3.5 =
> > 171.48.  Which is close enough to 168.89 that it doesn't explain the
> > 2mm difference in button size.  Am I incorrect in my thought that
> > there is something else causing this discrepancy?
>
> > 2. What is your recommendation to display a relatively consistently
> > sized button?  Possibly have different layouts for extra large
> > devices, set the button dimensions to 50dip on regular devices, and
> > 75dip on extra large devices?
>
> > On May 12, 12:10 pm, Dianne Hackborn <hack...@android.com> wrote:
>
> > > Sorry as things are today you basically can't do this because many devices
> > > are not reporting the correct true screen dpi.  If they did, the correct 
> > > way
> > > to do this would be to use a physical unit for your dimensions --- that is
> > > "10mm" if you want 10mm.  But as I say, there are many devices out there
> > > that are not configured with the correct physical screen dpi do these 
> > > units
> > > are at this point not usable.
>
> > > On Thu, May 12, 2011 at 8:50 AM, Ab <abe.oppenh...@gmail.com> wrote:
> > > > I want to put a toolbar in my application. The toolbar will use
> > > > ImageViews as application buttons. I would like the ImageViews to be
> > > > the exact same size regardless device; by "same size" I mean that,
> > > > when rendered to the screen, if I measure them with a ruler, the
> > > > dimensions will be the same. I would like this size to be ~10mm (the
> > > > width of my index finger).
>
> > > > I have been completely unsuccessful in accomplishing this.
>
> > > > I am testing on a MDPI, large screen Acer Iconia Tab and a HDPI medium
> > > > screen Samsung Galaxy Tab. If I set layout_width="50dip" and
> > > > layout_height="50dip", the buttons render as ~10mm on the Samsung, and
> > > > ~8mm on the Acer. If I set the buttons as layout_width="12mm" and
> > > > layout_height="12mm", they render as 12mm on the Acer and ~9mm on the
> > > > Galaxy (confusing that 50dip renders bigger on the Galaxy than the
> > > > Acer, but 12 mm renders smaller on the Galaxy than on the Acer).
>
> > > > If I place a 32pix x 32pix icon in my drawable-mdpi folder (and no
> > > > equivalent in the drawable-hdpi folder), and set
> > > > layout_width="wrap_content" and layout_height="wrap_content"; the
> > > > results are similar to if set to 50dip, the Samsung is about 10mm, the
> > > > Acer about 8mm. If I add a 48pix x 48pix icon to my drawable-hdpi
> > > > folder, there is no change; presumably because the Acer still uses the
> > > > mdpi icon and the Samsung uses the bigger one, but scales it down by
> > > > 50% because it knows its hdpi (if am confident that this surprising
> > > > scaling occurs because if I move the 48pix icon to the mdpi folder,
> > > > and have nothing in the hdpi folder, the icon shows very large on the
> > > > Samsung).
>
> > > > I then attempted to calculate the number of pixels necessary for 10mm
> > > > based on the values of xdpi and ydpi from DisplayMetrics: 10 mm in
> > > > pixels = xdpi * 10 / 25.4.  On the galaxy, this is  168.89 * 10 / 25.4
> > > > = 66.  However, when I set the layout_width to 66, the button measured
> > > > ~8mm wide.  But, at 168.89 dpi, the dots per mm should be 6.64
> > > > (168.89/25.4), so 66pixels should be approximately 10mm.  So, how
> > > > could it measure 8mm?  The Galaxy must be scaling down the layout
> > > > parameters somehow. Is there any way to retrieve how much they are
> > > > scaling down by, so that I can adjust for it?
>
> > > > I am confused and could really use advice. How do I make my button
> > > > fingertip sized regardless of dpi and screen size?
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "Android Developers" group.
> > > > To post to this group, send email to android-developers@googlegroups.com
> > > > To unsubscribe from this group, send email to
> > > > android-developers+unsubscr...@googlegroups.com
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/android-developers?hl=en
>
> > > --
> > > Dianne Hackborn
> > > Android framework engineer
> > > hack...@android.com
>
> > > 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to