Search code examples
javaandroidscreenandroid-notification-bar

Odd behavior of screen height in pixels?


In my android application, there is an OpenGL Renderer over-layed over a canvas. The device i'm testing on is a Droid x.

I'm moving all the drawing functions over to Open Gl but I've noticed a curious issue.

It seems that the canvas draws starting at immediately after the notification bar, but the GL render starts at the tip of the screen.

This is a little important because the physics of my game are based on the metrics of the screen as they were drawn in the canvas.

Ideally, I think I could solve the problem by somehow shifting the GLview down by the height of the notification bar, but i'm not sure how to do this or if its possible.

Changing the following code seems to make it look correct from my application, but I need a way to make it more cross-platform safe.

I fix it by changing...

gl.glViewport(0, 0, width, height)

to

gl.glViewport(0, -38, width, height) 

Solution

  • Do you use multiple drawable folders? on one of my apps i use the following code, which is based on getting the dimensions of the drawable the phone selects.

    image = bgtile.getWidth();
    
    if (image == 32) {
            gl.glViewport(0, -19, width, height) 
        }
        if (image == 42) {
            gl.glViewport(0, -25, width, height) 
        }
        if (image == 64) {
            gl.glViewport(0, -38, width, height) 
        }
    

    If the phone selects the ldpi image, it does the first if, mdpi the second and ldpi the third. just change the 32, 42 and 64 to the size of you image.