How do you get the width and height of a surface view
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
精彩评论