• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Canvas, Aspect Ratio, and Resolution Independence

2entysix

Lurker
I've stumbled into an interesting issue dealing with drawing images to a canvas (SurfaceView to be precise). I'm working on a simple game, and I'd like to have it play well with a variety of aspect ratios and resolutions. Hence, I've constructed the base background in a smaller aspect ratio so that I can simply add "bars" (blank space areas) to make it fit longer screens. While this solution is fine with me (unless a better one exists which I am unaware of), Things get more difficult when I want to add these "bars" (blank space to pad the sides of the centered background).

First off, to get the background bitmap centered, I'm trying to go about by getting the screen measurements and working out the difference between the scaled image and the screen. This seems inelegant, however. Likewise, it opens up a whole new can of worms. From this point, I need to treat all coordinates (such as those used fro drawing units in the game) relative to the image and NOT the screen. Even if I figure out this data in pixels, it still lacks the resolution independence that dips have... Perhaps separating this quality into the view itself (have the canvas be centered with the background size) might be a better solution?

I feel like I'm going about this in a rather obtuse way, and am curious if you guys have any pointers for dealing with this sort of issue. I'm very new to Android and Graphics (as well as UI) programming in general, so any advice for dealing with this will be very useful!
 
Back
Top Bottom