0

我刚刚在 android 上发布了我的应用程序,并遇到了高密度显示器客户的问题。

我添加了一个调试东西来看看发生了什么,这是一个示例输出

设备:Nexus 10 Android 版本:4.2.2 DisplayMetrics{density=2.0, width=2560, height=1504, scaledDensity=2.0, xdpi=298.275, ydpi=298.823} MainView w=1900 h=1342 mDrumKitMode=BIG KitView w=640 h=1266 x=1920.0 y=0.0

主视图是屏幕截图左侧的乐谱区域,其 1900 宽(MainView w=1900 h=1342)鼓组是 640w 和 640 高的位图。不知何故,显示器将其缩放为父级的全高(KitView w=640 h=1266 x=1920.0 y=0.0)。这不会发生在密度 = 1.0 的显示器上。

我无法对此进行测试,因为由于某种原因我无法让模拟器在大显示器上工作,而且我没有高密度平板电脑。

有谁知道会发生什么?谢谢

在此处输入图像描述

这是另一个有类似问题的客户

设备:A700 Android 版本:4.1.1 DisplayMetrics{density=1.5, width=1920, height=1128, scaledDensity=1.5, xdpi=224.73732, ydpi=224.11765} MainView w=1260 h=1044 mDrumKitMode=BIG KitView w=640 h =968 x=1280.0 y=0.0

我认为它的 scaledDensity=1.5 参数,也许我需要做一些事情来禁用自动图像缩放,即设置 scaledDensity=1?

i should add that the entire application is based on exact pixel positions, both for the music notation display and the drum kit display which overlays images on top of the base drum kit image (you can see the drum pedals are in the wrong place on this image too). i don't want automatic scaling as i handle scaling inside the app for different display sizes and user preferences.

i should also add that all my drum kit images are in drawable-mdpi and all the other dpis are empty. this is because i scale images programmatically based on screen size and user preference BUT i think maybe the problem is a need to put some images in xhdpi? i guess i can do that but it will be a lot of work.

PS, i guess i found my answer here http://developer.android.com/guide/practices/screens_support.html

Provide different bitmap drawables for different screen densities

By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and Nine-Patch drawables (.9.png files) so that they render at the appropriate physical size on each device. For example, if your application provides bitmap drawables only for the baseline, medium screen density (mdpi), then the system scales them up when on a high-density screen, and scales them down when on a low-density screen. This scaling can cause artifacts in the bitmaps. To ensure your bitmaps look their best, you should include alternative versions at different resolutions for different screen densities.

i wonder if simply copying all the -mdpi images to -xhdpi will work?

4

1 回答 1

1

如果您打算跨设备使用此应用程序,您别无选择,只能为存在的所有各种密度文件夹(xhdpi、xxhdpi、hdpi、mdpi)放入图像。还值得考虑的是,您可能想要更改包含的实际布局,以便为不同的设备提供不同的布局。

请参阅文档以了解如何处理此问题。 http://developer.android.com/guide/practices/screens_support.html

如果这会创建一个太重的 apk(我不知道您有多少图像),那么您可以采用另一种方式并指定一个不可缩放的可绘制文件夹,该文件夹将只使用跨设备的原始密度的图像。除非您打算仅支持 mdpi 设备,否则仅使用 mdpi 绝对是错误的。

于 2013-03-31T01:04:00.183 回答