Android 屏幕分辨率和尺寸

发布于 2024-09-29 09:03:04 字数 373 浏览 0 评论 0原文

我目前正在开发一个 Android 应用程序,这给我带来了一些麻烦。我的应用程序严重依赖于正确适合其所显示屏幕的图像。不幸的是,像 FWVGA/WVGA 分辨率差异 854 与 800 这样的事情给我带来了一些真正的问题,这还不包括其他尺寸/密度和分辨率。

我不知道我是否只是错过了这里的重点,但是我如何让我的应用程序在两种分辨率上正确显示,而不“挤压”我的图像或削减给我黑条等的部分?

似乎没有立即存在的解决方案,我可以让它自动从右侧屏幕的可绘制文件夹中显示不同的图像。

我尝试过使用 displaymetrics,但除非我明确声明它支持所有屏幕尺寸,否则 Android 操作系统实际上会在当前分辨率方面对我的应用程序“撒谎”。

有人请告诉我有一个简单的解决方案。

I am currently working on an android app that is causing me some trouble. My app is heavily dependent on images that are fitted correctly to the screen they are being displayed on. Unfortunately things like the FWVGA/WVGA resolution difference 854 vs 800 is causing me some real problems, and that's aside from the other sizes/densieites and resolutions.

I don't know if I'm just missing the point here but how do I go about having my app display correctly on both the resolutions without either "squashing" my images or cutting bits off of giving me black bars etc?

There doesn't seem an immediately present solution where I can just have it display a different image automatically from the drawable folder for the right screen.

I have tried using displaymetrics but unless i have my manifest claim that it supports all screen sizes, the android OS will in fact "lie" to my app about hte current resolution.

Someone please tell me there is an easy solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

另类 2024-10-06 09:03:05

如何让我的应用程序在两种分辨率下正确显示,而不“挤压”我的图像或削减黑条等内容?

恕我直言,您首先要重新审视 GUI 设计:

我的应用程序严重依赖于正确适合其所显示屏幕的图像。

恕我直言,这在任何地方都不是特别有效。例如,Windows(包括浏览器)可以由用户调整为任何所需的大小。

似乎没有立即存在的解决方案,我可以让它自动从右侧屏幕的可绘制文件夹中显示不同的图像。

因为 Android 设备可以有任意数量的屏幕尺寸,就像 Windows 和 Web 浏览器可以有任意数量的屏幕尺寸一样。 Android 确实允许您根据密度(例如,-hdpi)或屏幕尺寸(例如,-large)选择图像,但这些不会映射到分辨率,也不应该映射到分辨率。

how do I go about having my app display correctly on both the resolutions without either "squashing" my images or cutting bits off of giving me black bars etc?

IMHO, you start by revisiting your GUI design:

My app is heavily dependent on images that are fitted correctly to the screen they are being displayed on.

That does not work particularly well anywhere, IMHO. Windows (including browsers) can be sized to any desired size by the user, for example.

There doesn't seem an immediately present solution where I can just have it display a different image automatically from the drawable folder for the right screen.

Because Android devices can have any number of screen dimensions, just like windows and Web browsers can have any number of screen dimensions. Android does let you choose images based on density (e.g., -hdpi) or screen size (e.g., -large), but these do not map to resolutions, nor should they.

夏尔 2024-10-06 09:03:05

正如 CommonsWare 指出的,针对这种情况,最好的选择实际上是重新考虑布局结构。使用RelativeLayouts 和小部件,可能可以实现与您当前拥有的结果相似(即使不完全相同)的结果。如果您愿意发布样本,我们可以为您提供相关方法的建议。

也就是说,您问题的答案是在运行时查询设备的屏幕分辨率(请记住通知栏以及标题栏占用的空间 - 除非您在没有标题栏的情况下对其进行主题化)。对于每种可能的屏幕分辨率,您都需要不同的图像,并且随着更多设备(尤其是平板电脑)开始发布,您将必须在发布时继续为每个不同的图像提供更多图像和自定义代码。您会明白为什么这不是一个理想的情况。

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int screenWidth = metrics.widthPixels();
int screenHeight = metrics.heightPixels();

然后,您可以将其放入 if-then-else 块中,确定分辨率,并相应地设置图像。我不推荐这个。

As CommonsWare pointed out, your best bet for this situation really is to rethink your layout structure. It's probably possible to accomplish similar, if not identical results to what you currently have, using RelativeLayouts and widgets. If you're willing to post a sample, we could advise you on ways to do so.

That said, an answer to your question would be to query the device at runtime for its screen resolution (keeping in mind space taken up by the notification bar, as well as the title bar - unless you theme it without a title bar). You would need a different image for every possible screen resolution, and as more devices (notably tablets) begin to release, you're going to have to continue to provide more images and customized code for each different image as they release. You can see why this is not an ideal situation.

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int screenWidth = metrics.widthPixels();
int screenHeight = metrics.heightPixels();

Then you can place that into an if-then-else block, and determine the resolution, and set the image accordingly. I don't recommend this.

笑,眼淚并存 2024-10-06 09:03:05

当涉及到显示器和分辨率时,如果不挤压/拉伸图像或使用信箱,就不可能将图像调整为任何纵横比。我知道这并不能真正回答您的问题,但如果您无法从操作系统获得可靠的屏幕尺寸信息,请尝试选择最大分辨率的图像并裁剪较小的分辨率。只要确保边界周围没有任何有趣的东西即可。

When it comes to displays and resolutions, it is not possible to have your images resized to any aspect ratio without either squishing / stretching them, or using letterboxes. I know this doesn't really answer you question, but if you can't get reliable screen size information from the OS, then try picking images for the largest resolution and cropping them for the smaller resolutions. Just make sure there is nothing interesting around the borders.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文