Search code examples
androidandroid-canvassurfaceview

Android: SurfaceView resolution is lower than screen resolution


I am following a tutorial on http://obviam.net/index.php/a-very-basic-the-game-loop-for-android/ to make an Android game loop. It works really well, except that my SurfaceView is only 526x320 while my phone is 1920x1080 resolution. Can anyone help me fix this issue?


Solution

  • First, that tutorial overrides onDraw() when rendering onto a SurfaceView Surface, which is a recipe for trouble. Don't do that. Don't extend SurfaceView unless you really want to draw on the View as well as the Surface. (Its render thread may also continue to run while the app isn't in the foreground... maybe you should find a tutorial by someone who understands SurfaceView better.)

    Second, the SurfaceView's Surface is allowed to be a different size. You can set it to any (reasonable) size you want with the setFixedSize() method.

    The default size of the SurfaceView should match the size of the View. If you have a full-screen View, the Surface will be the size of the screen.