Saturday, 3 January 2015

I'm Your Density

It's nice when a hunch turns out to be right. Yesterday, I was baffled by my bitmaps being cropped to one corner and suspected something to do with pixel densities.

After reading much stuff on Stack Overflow and finding a very helpful video on YouTube, I discovered some useful information about how to properly support Android displays. As there are thousands of different devices with many screen sizes and resolutions, Android simplifies this by categorizing devices into 'buckets' labelled medium, high, extra-high definition etc.

Life's a medium density maze
I'd been using actual pixel sizes on an extra-high def. (XHDPI) screen which doesn't work correctly. The baseline is medium density where a physical pixel equates to a device independent pixel, or 'dip'. A dip on my XHDPI Nexus 4 is 2x2 pixels which explains why all my graphics were being chopped into quarters yesterday.

This evening, I've got part of my test map (yes, Pacman) displaying correctly, without any artifacts and learned that I'll need to make multiple copies of all my graphics in order to support the various buckets. This is frankly a bit of a bind but it's handy to know early on that I'll need to be doing this.

For now I can just work at XHDPI, produce my graphics for that level and make resized versions later when testing on different devices.