Handling Different Screen Sizes and Resolutions

Android has supported different screen resolutions since version 1.6; it can handle resolutions ranging from 240! 320 pixels to a much beefier 480! 854 pixels on some new devices (in portrait mode; for landscape mode, just swap the values). In the last chapter we already saw the effect of these different screen resolutions and physical screen sizes: drawing with absolute coordinates and sizes given in pixels will produce unexpected results. Figure 5-1 shows you once more what happens when we render a 100! 100-pixel rectangle with the upper-left corner at (219,379) on 480! 800 and 320! 480 screens.

Figure 5-1. A 100x100-pixel rectangle drawn at (219,379) on a 480x800 screen (left) and a 320x480 screen (right)

This difference is bad for two reasons. First, we can't just draw our game assuming a fixed resolution. The second reason is subtler ,however. In Figure 5-1, I silently assumed that both screens have the same density (i.e., that each pixel has the same physical size on both devices), but this is hardly the case in reality.

Was this article helpful?

0 0

Post a comment