开发者

Android emulators not simulating correct density or resolution. Possibly a surfaceview implementation issue

开发者 https://www.devze.com 2023-01-22 14:34 出处:网络
I’m building a small app that is using a surfaceview class that extends surfaceholder.callback.It is implemented just like the lunarlander example.My problem is that each type of emulator I use (low,

I’m building a small app that is using a surfaceview class that extends surfaceholder.callback. It is implemented just like the lunarlander example. My problem is that each type of emulator I use (low, medium or high density) doesn’t seem to actually change the density of the screen or the resolution to what I would expect. I recently asked this question on stack overflow and it is dawning on me that I’m not doing anything wrong with that function, the problem is that somehow any emulators I use are all getting recognize开发者_StackOverflowd at medium density.

The high density emulator screen shows very pixilated images. The medium density emulator images look fantastic. The low density emulator images look pixilated, but not as bad as the hdpi.

I did a mySurfaceHolder.getSurfaceFrame() on each emulator and came up with this:

  • WVGA800 - 480x800 - hdpi - generates a surface 320 x 508
  • Default(HVGA) - mdpi - generates a surface 320 x 455
  • QVGA - 240x320 - ldpi - generates a surface 320 x 402

Shouldn’t these surfaces be 480x800, 320x480 and 240x320 respectively? Edit: the 320x455 makes sense, the rest is probably taken up in the title bar. But what about the low/high?

So, I’m unsure if my problem is:

  1. How I’m setting up the emulator. – I use HVGA, QVGA, WVGA800, and WVGA854 with standard settings (no custom resolutions)

  2. Something wrong with my code in the surfaceview class. Note than I do not manually set a size, I rely on the size returned from this callback method:

.

public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
    thread.setSurfaceSize(width, height);
}

Any thoughts? As always, I appreciate all your help!


Well, chalk this up to an error in the android documentation I guess.

The problem is basically any emulator I use gets simulated as a medium density screen unless the following line is in the Android manifest file. All resources default to the mdpi folder and never get pulled from the hpdi folder. Some sort of scaling operation was then automatically performed since it treated the HDPI screen like an MDPI one, thus explaining the "pixelated" on-screen images.

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

The documentation states:

“android:anyDensity Indicates whether the application can accommodate any screen density. Older applications (pre API Level 4) are assumed unable to accomodate all densities and this is "false" by default. Applications using API Level 4 or higher are assumed able to and this is "true" by default. You can explicitly supply your abilities here. “

I am using API Level 8, and had to supply this line to simulate the screen at a high density setting.


Surface doesnt show you the working area? Excluding status bar and maybe application title bar. It could give you dips instead of pixels.

pixels = dips * (density / 160)

0

精彩评论

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