开发者

Android: SurfaceView canvas size different from target device pixels

开发者 https://www.devze.com 2023-04-07 22:18 出处:网络
I am new to Android programming. I have little game where I draw everything into offscreen canvas. When I want to present it I use calss derived from SurfaceView. It works OK. Problem is that offscree

I am new to Android programming. I have little game where I draw everything into offscreen canvas. When I want to present it I use calss derived from SurfaceView. It works OK. Problem is that offscreen canvas is 480x800 (target device resolution) pixels but SurfaceView canvas I get through getHolder().lockCanvas() is only 240x480. As a result it looks really ugly - it is first scaled down from offscreen canvas to SurfaceView c开发者_JS百科anvas (loosing small details) and then enlarged to fit device screen (stretched back to original size).

As the emulator is running also 480x800 I have no idea why the SurfaceView is created so small. Why it is not created in the size of emulated device? I finally bypassed it with setting fixed size of holder (getHolder().setFixedSize(480, 800)) but is this correct way?

Is there any other way how to force device to create SurfaceView in size of its pixels?


Try adding this to your manifest outside the application tag.

<supports-screens android:anyDensity="true" />
0

精彩评论

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

关注公众号