0

I Have a few general questions about Android screen / DPI / resolution indepence.

Basically, I am taking specifically about sprite-based apps, like ones based on Surfaceview for example.

Every guide I've read (including the official one) says that you should only work with the DPI and not the resolution.

However, what happens when two devices have different DPI's/screen size but the same resolution? Take the Galaxy tab 10.1 (1280 x 800 - DPI aprox 150) and the Galaxy Note (1280 x 800 aprox 285 DPI I think??)

When displaying a sprite of say 50 x 50 on each of these, it will appear to be the same size relative to the screen size. However, if Android grabs a difference size sprite because it detects a different DPI (ie, from LDPI, HDPI etc), then the sprite will appear to be bigger on the Note relative to the screen size than it would on the Tab.

Can anyone please set me straight on this as I just cannot work it out!! Thanks all.

COD3BOY
  • 11,964
  • 1
  • 38
  • 56
Paul Butt
  • 11
  • 2
  • Have you read the dev guide for supporting multiple screens? It explains about how to plan image sizes for the different drawable resources as well as explaining how Android generalizes different devices based on screen size and density. http://developer.android.com/guide/practices/screens_support.html – Squonk Jan 04 '12 at 02:03

1 Answers1

3

A 50 x 50 sprite on a 150dpi screen will appear much larger than a 50 x 50 sprite on a 285dpi screen. Android's resource resolution algorithm is intended to allow you to define a larger (in pixels) image for use on higher density screens.

If you want the sprite to be the same size relative to the screen regardless of the pixel density, then you can put the images in the drawable-nodpi folder and they won't be scaled by the system. You can even decide which size image to use in code after querying the screen size. (As of 3.2, you can have resource folders that depend on screen pixel size, but I think they will still scale with dpi.)

Screen resolution refers to the screen dimension in pixels. Pixel density refers to how many pixels it takes to fill an inch of screen.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • Thanks Ted. If I use a 50x50 image on the tab and a 50x50 on the Note, the relative size would be the same & this is what I'm afer, I didn't know about the drawable-nodpi folder so thanks! However, I still want to use different size images for different resolutions. (ie, if I used the 50x50 on an 800x480 screen, it would appear too big (relative to the screen) so are there resolution specific folders similar to the DPI ones too? Should I name my folders 'small', 'normal', 'large' and 'xlarge' - I didn't realise these could contain resource files, always thought they were for layouts! Thanks – Paul Butt Jan 04 '12 at 23:10
  • @PaulButt - You can use resource type qualifiers for any kind of resource. You can also combine it with pixel density (or other attributes), so you could have, for instance, `drawable-large-hdpi` and `drawable-large-mdpi`. How this works and the rules for doing this are described [here](http://developer.android.com/guide/topics/resources/providing-resources.html). As of 3.2, there's a better way to target screen sizes, as described [here](http://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts). – Ted Hopp Jan 05 '12 at 01:37