开发者

How do you get the width and height of a surface view

开发者 https://www.devze.com 2023-01-22 01:42 出处:网络
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.

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 co开发者_如何学Pythonded 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.


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();
      }
    }
);


You probably need to do something like this:

Determining the size of an Android view at runtime

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号