Take the 2-minute tour ×

i recently developed a game, for Android 2.3.3, and strangely im finding few weird behaviour in different phones,

for example

  1. An explosion sprite(256x256 pixels) divided into 4x4=16 images, when displayed is being displayed as a 2x2 image in Samsung Galaxy Ace 2.3.3 and Samsung Galaxy Y, 2.3.5 ,

  2. Also, the accelerometer works in a haphazard form in Sony Xperia 2.3.3 and Samsung Galaxy Ace.. either its too slow(and takes touch gestures after 3-4 second gap) and Android OS throws a Alert box saying, the app is not responding, else its too fast.

Strangely, The game works perfectly on a Samsung S2, just like it plays on the VirtualBox..

please help me, b'cos this is my college project, and I wont even be able to put this up in the market if such a queer problem exists!!

Thanks in Advance!!

share|improve this question
Could you post some of the code for drawing your explosion sprites? –  nvuono May 6 '12 at 7:45
Which Sony Xperia device you are referring to? –  Anup May 9 '12 at 22:38
int srcX = column * width_explosion; int srcY = row * height_explosion; Rect src = new Rect(srcX, srcY, srcX + width_explosion, srcY + height_explosion); Rect dst = new Rect((int) (x1 - width_explosion / 2), (int) (y1 - height_explosion / 2), (int) (x1 + width_explosion / 2), (int) (y1 + height_explosion / 2)); canvas.drawBitmap(random_explosion, src, dst, null); column = ++column % 4; if (column == 0) { row++; } if (row == 4) { explosion_drawn = true; row = 0; } –  Mahesh Aug 9 '12 at 17:11

2 Answers 2

I think I have the same experience with the graphics problem:

From your code, I'm guessing you may have pre-computed "width_explosion" and "height_explosion" from the image height/width you have seen in an image editor and using the same values on different devices.

The device you have listed have two different DPI values as Android knows: 240, or MDPI (Galaxy S2) and 120, or LDPI (Galaxy Ace and Galaxy Y). Note that Galaxy S2's DPI is exactly twice as Ace's and Y's.

Android makes it handy for app authors by assisting them in manipulating images. When images are read from resources through getDrawable and are ready for rendering on screen Android resizes the images with respect to 160DPI, so that they will have the same length measured with a ruler on screens with different pixel densities. For example, if an image with 128x128 pixels is 2cm long and 2cm wide on Galaxy S2, it should be 2cm long and 2cm wide on a Galaxy Ace. However, to cover the more pixels on a Galaxy S2, it's resized to 192 x 192 pixels when drawing on a Galaxy S2, because its DPI as the Android system knows it is 240, 1.5 times the DPI of an ADP1 (HTC Dream). Similarly, the image will be resized to 96 x 96 on a Galaxy Ace or Galaxy Y.

The source rectangle in canvas.drawImage, unfortunately, refers to the number of pixels in the resized bitmap. That means the same source rectangle used in your code sample covers 4 times as many pixels on a Galaxy Y as it does on a Galaxy S2. I guess you are describing in the question that "the same sprite file looks like it was divided in 2x2 on a low DPI device but it should be divided by 4x4".

The following example illustrates what happens when I'm trying to replicate your question with devices with different DPIs. I cannot post images, so I have put the images here (it's my blog):


share|improve this answer

Not sure what to do about the graphics issue, but for the accelerometer each device acts differently. Use event.sensor.getMaximumRange() in your onSensorChanged() to get the maximum value and base your actions on that or a percentage of that.

share|improve this answer

Your Answer


