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

Apps Wrong screen size

wazzzup

Lurker
I have a HTC Desire and I'm developing a game. I noticed that the dimensions I get from the surfaceChanged callback is 320 x 508 in portrait and 533 x 295 in landscape orientation. This seems too small since the physical screen is 480 x 800. The width from surfaceChanged should be 480 and the heigth should be slightly less because of the status bar.

Drawing a rectangle with the dimensions from the callback fills out the whole screen!

I have upgraded to Froyo.

Am I missing something?
 
Are you using DisplayMetrics to get the screen size? Also when drawing to a canvas you can use the Canvas.getWidth() and Canvas.getHeight() methods which should give you the correct dimensions. Not sure if you have tried that or not but thought I would I ask.
 
Now I have tried both. DisplayMetrics gives a size of 320 x 533 which is consistent with 320 x 508 and 533 x 295 which is the drawable area. canvas.getWidth () and Height () gives the same as the surfaceChanged callback.

Here are all values from DisplayMetrics:

Code:
DisplayMetrics{density=1.5, width=320, height=533, scaledDensity=1.5, xdpi=254.0, ydpi=254.0}

public float   density        The logical density of the display.
public int     densityDpi     The screen density expressed as dots-per-inch.
public int     heightPixels   The absolute height of the display in pixels.
public float   scaledDensity  A scaling factor for fonts displayed on the display.
public int     widthPixels    The absolute width of the display in pixels.
public float   xdpi           The exact physical pixels per inch of the screen in the X dimension.
public float   ydpi           The exact physical pixels per inch of the screen in the Y dimension.
It seems that the "real" height is heightPixels * density, which is a bit weird. "The absolute height of the display in pixels" should be just that, IMHO.

I also noticed that coordinates for drawing primitives are floats. This means that they should never be rounded off to integers when drawing.
 
hmmmm... yea that would make sense. Now in your activities onCreate() are you drawing to a place holder such as a SurfaceView or FrameLayout? If so after you get a handle to that layout you should be able to call getHeight() and getWidth() from there on that view. If not you should also be able to do something like...

Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();

... to get the absolute height and width of the screen in pixels.

Let me know if that works, I find it interesting that it is returning those dimensions.
 
I draw to a SurfaceView.

Code:
Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();
int height = display.getHeight();

This also gives 533 x 320.

The drawing I do looks good, so there is really no problem. It's just weird.
 
Back
Top Bottom