views:

80

answers:

1

Hi everyone !

I think I might be about to ask a dummy question, but I'm still new with Android programming, and I couldn't (despite all my efforts) find my answer on Google.

The thing is, I'm trying to develop a little game, with 2D Graphics. I want my "gaming board" to be at a specific position on my screen, so that I can display in-game informations above and below the box. But since there is beginning to be a lot of Android phones out there, I was thinking about getting "dynamic" values so that I can adapt my font size to every device.

My game is not in full screen (but it could be, it's no big deal), but in a window with no title bar.

I'm using an extension of the default SurfaceView class, implementing SurfaceHolder.Callback. I tried writing the following method :

public void getViewSize()
    {
        VIEW_WIDTH = this.getWidth();
        VIEW_HEIGHT = this.getHeight();
    }

but the values returned are zeroes.

Anyone got an idea (even if it means changing display strategy) ? Thanks a lot.

A: 

You can do this:

public void onDraw(Canvas canvas) {
  VIEW_WIDTH = canvas.getWidth();
  VIEW_HEIGHT = canvas.getHeight();
}
xil3
Thank you, I'll try this at lunch and tell you if it worked
Squ36
Yeah it worked perfectly fine !!!! Thanks a lot !
Squ36
I want to do the exact same thing but the control never enters my onDraw() method. Please take a look at this question:http://stackoverflow.com/questions/3340847/subclassing-surfaceview-and-overriding-ondraw-to-change-surfaceview-parameters
Namratha