I make the game and use SurfaceView to draw objects and in the SurfaceChanged method I get the height and width of the View. Here is the code snippet:

public void surfaceChanged(SurfaceHolder arg0, int format, int width, int height) { mViewWidth = width; mViewHeight = height; System.out.println(mViewWidth+" "+mViewHeight); } 

It turns out that the width and height of View 320x403. But the resolution of my screen is 320x240. How is this possible !?

    1 answer 1

    View sizes are not tied to the size of the physical screen: you can create a view of both smaller and larger screen. The view is wider than the screen scrolls horizontally, and the view is longer than the screen - vertically.

    In addition, the SurfaceView may not return pixels, but dipy (pixels = dipy * (density / 160));

    • But here such a thing, I indicate the coordinates of the object (0.320) for drawing. I expect that it will be at the very bottom of the screen, but it is not at the very bottom of the screen. If you specify the coordinates (0.400), then it will be at the screen itself. How to understand this? - uLtimAte
    • You can try: LayoutParams params = new LayoutParams (width, height); surfaceView.setLayoutParams (params); - stanislav