tags:

views:

29

answers:

3

I am developing a game.I have drawn images on a surface view which is residing in a relative layout.I want that my game's look and feel should be the same in all resolutions. So now i want to measure the surfaceview/canva's width and height so that I can launch the images in proper proportion rather than hard coded values. But I am unable to retrieve the height and width so please help me.

  I tried canvas.getWidth() and all but it returns 0.
A: 

Could it be getWidth() you are looking for? This gets the width of the view.

icecream
I guess not :-)
icecream
+1  A: 

Maybe it is because you try to get the width too soon.

Try this:

canvas.post(new Runnable()
    {
      public void run()
      {
        int w = canvas.getWidth();
      }
    }
);
GôTô
This is more than likely correct, I've had the same problem in the past.