android - 应用程序的屏幕分辨率
我是 Android 新手,刚刚开始创建一个应用程序。 我想为我的应用程序放置背景图像。 我必须使用的图像的宽度和高度是多少,以便它可以在所有设备上运行。
I am new to Android and I just started creating an application.
I want to place a back ground image for my app.
What is the width and height of the image that I've to use so that it works on all the devices.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这涉及到几个不同的概念。虽然这两个内容都包含在相当长且神秘的支持多屏幕文档中,但让我先提醒一下。
您可能需要阅读该文档几次。
设备按像素密度和屏幕尺寸分组。像素密度为低 (ldpi)、中 (mdpi)、高 (hdpi) 和新的超高 (xhdpi) 之一。屏幕尺寸有小、普通、大和新款超大。此外,还有两种方向:纵向和横向。如果您查看实际接触Android Market的内容,您可以忽略除普通屏幕的 mdpi 和 hdpi。
这些分组对应于项目的 res/ 目录树下的单独目录。在 res/drawable 中放置所有通用图像。当您覆盖了基本类型的 res/drawable-mdpi 和 res/drawable-hdpi 后,将图像放入 res/drawable-mdpi 和 res/drawable-hdpi 中。
此外,这些分组在“中密度”(约 140 至 180 dpi)和“高密度”(约 170 至 250 dpi)之间有重叠。作为参考,摩托罗拉 Droid X 的手机尺寸为 854 像素 x 480 像素,显示屏尺寸为 4.7 英寸(对角线),密度为 217 dpi。
您通常以预缩放单位指定布局资源(图形的 dp,每英寸间隔 1/160 或文本中的 sp 等效值)。请参阅此问题了解更多信息。
不同的测量结果毫无必要地令人困惑。制作大约 640 x 480 的 mdpi 图像和大约 800 x 600 的 hdpi 图像,您应该是正确的。另外,无法保证长宽比,您可能需要使用 9-patch 工具来确保其正确拉伸。
如果您确实想要查看设备分辨率,您可以询问 getWindowManager().getDefaultDisplay().getWidth()/.getHeight() 像素数。
快乐编码!
This touches a couple of different concepts. While both are covered in the rather long and cryptic Supporting Multiple Screens document, let me give a few heads up.
You might need to read the document a few times.
Devices are grouped by pixel density and screen size. Pixel density is one of low (ldpi), medium (mdpi), high (hdpi), and the new extra-high (xhdpi). Screen sizes or small, normal, large, and the new extra-large. Also, there are two orientations: portrait and landscape. If you look at what actually contacts the Android Market, you can ignore everything except mdpi and hdpi for normal screens.
These groupings correspond to separate directories under the res/ directory tree of your project. In res/drawable go all your generic images. In res/drawable-mdpi and res/drawable-hdpi go your images when you have overridden them for the basic types.
Also, these groupings have overlap between "medium density" (about 140 to 180 dpi) and "high density" (about 170 to 250 dpi). For reference, the Motorola Droid X has a 854 pixel by 480 pixel phone in a 4.7" (diagonal) display for a density of 217 dpi.
You generally specify your layout resources in prescaled units (dp for graphics, at 1/160 per inch intervals or sp equivalent in text). See this question for more information.
The different measurements are needlessly confusing. Make a mdpi image at about 640 x 480 and a hdpi image at about 800 x 600 and you should be about right. Also, the aspect ratio is not guaranteed, you may need to use the 9-patch tool to make sure it stretches correctly.
If you really want to see the device resolution, you can ask for the getWindowManager().getDefaultDisplay().getWidth()/.getHeight() number of pixels.
Happy Coding!
由于android没有任何特定的分辨率。我们需要通过不同的可绘制文件夹来实现。最好参考这个链接
Since android doesn't have any specific resolution. We need this by different drawable folders. Better to refer this link