简体   繁体   English

用于 ldpi、mdpi、hpdi 的 Android 屏幕尺寸(以像素为单位)?

[英]Android screen sizes in Pixels for ldpi, mdpi, hpdi?

I've read 10 articles yet still cant find any relation between ldpi, mdpi, hdpi and the actual dimensions in pixels!?我已经阅读了 10 篇文章,但仍然找不到 ldpi、mdpi、hdpi 和以像素为单位的实际尺寸之间的任何关系!? Can anybody give a straightforward answer please(if there is one!)任何人都可以给出一个直截了当的答案吗(如果有的话!)

I'm basically trying to put together a splash screen that needs to work on multiple devices without stretching - but i'm struggling as everything I try is either squashed or stretched!?我基本上是在尝试组合一个需要在多个设备上工作而无需拉伸的启动画面 - 但我很挣扎,因为我尝试的所有东西要么被压扁,要么被拉伸!?

Cheers Paul干杯保罗

The ldpi, mdpi and hdpi refer to screen density, which means how much pixels can fit into a single inch. ldpi、mdpi 和 hdpi 指的是屏幕密度,即一英寸可以容纳多少像素。

the ratio in pixels between them is:它们之间的像素比为:

  • ldpi = 1:0.75 ldpi = 1:0.75
  • mdpi = 1:1 mdpi = 1:1
  • hdpi = 1:1.5 hdpi = 1:1.5
  • xhdpi = 1:2 xhdpi = 1:2
  • xxhdpi = 1:3 xxhdpi = 1:3
  • xxxhdpi = 1:4 xxxhdpi = 1:4

so lets take an image with about the size of 100X100:所以让我们拍摄一个大约 100X100 大小的图像:

  • for mdpi it should be 100X100对于 mdpi,它应该是 100X100
  • for ldpi it should be 75X75对于 ldpi,它应该是 75X75
  • for hdpi it should be 150X150对于 hdpi,它应该是 150X150
  • for xhdpi it should be 200X200对于 xhdpi,它应该是 200X200
  • for xxhdpi it should be 300X300对于 xxhdpi,它应该是 300X300
  • for xxxhdpi it should be 400X400对于 xxxhdpi,它应该是 400X400

this way, for screens with the same size but different DPI, all the images seem the same size on screen.这样,对于大小相同但 DPI 不同的屏幕,所有图像在屏幕上看起来都相同。

Also you have multiple screen size types small, normal, large, xlarge and each one of them can be ldpi, mdpi, hdpi, xhdpi, xxhdpi (Nexus 10) or xxxhdpi.此外,您还有多种屏幕尺寸类型:small、normal、large、xlarge,每一种都可以是 ldpi、mdpi、hdpi、xhdpi、xxhdpi(Nexus 10)或 xxxhdpi。

You can try to create a splash screen image that fit to each and every screen type which gives you 4*5 = 20 different images (it seems to much for me).您可以尝试创建适合每种屏幕类型的初始屏幕图像,它为您提供 4*5 = 20 个不同的图像(对我来说似乎很多)。

For now only the Nexus 10 is at the xxhdpi category.目前只有 Nexus 10 属于 xxhdpi 类别。

Install ImageMagick and use this shell script to generate your splash and icon files for multiple devices - iOS, Android, Bada and Windows Phone.安装 ImageMagick并使用此 shell脚本为多个设备(iOS、Android、Bada 和 Windows Phone)生成启动画面和图标文件。 You can use cygwin/gitbash if you are on Windows如果你在 Windows 上,你可以使用 cygwin/gitbash

I just did and I'm pretty happy with it :-)我刚刚做到了,我对此很满意:-)

The screen sizes are inside the script and are -屏幕尺寸在脚本内,是 -

480x800 - screen-hdpi-portrait.png
320x200 - screen-ldpi-landscape.png
720x1280 - screen-xhdpi-portrait.png
320x480 - screen-mdpi-portrait.png
480x320 - screen-mdpi-landscape.png
200x320 - screen-ldpi-portrait.png
800x480 - screen-hdpi-landscape.png

The definitions are:定义是:

  • xlarge screens are at least 960dp x 720dp. xlarge 屏幕至少为 960dp x 720dp。 large screens are at least 640dp x 480dp.大屏幕至少为 640dp x 480dp。 normal screens are at least 470dp x 320dp.普通屏幕至少为 470dp x 320dp。 small screens are at least 426dp x 320dp.小屏幕至少为 426dp x 320dp。 (Android does not currently support screens smaller than this.) (Android 目前不支持比这更小的屏幕。)

Also, check out this blogpost from Dianne Hackborne: http://android-developers.blogspot.com/2011/07/new-tools-for-managing-screen-sizes.html另外,请查看 Dianne Hackborne 的这篇博文: http : //android-developers.blogspot.com/2011/07/new-tools-for-managing-screen-sizes.html

Probably the easiest thing is to use an image view and set the scaletype to CENTER_CROP.可能最简单的方法是使用图像视图并将 scaletype 设置为 CENTER_CROP。 (Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view). (均匀缩放图像(保持图像的纵横比),使图像的两个尺寸(宽度和高度)等于或大于视图的相应尺寸)。

Make sure that you use the src tag rather than setting the background.确保使用 src 标签而不是设置背景。

<ImageView
   android:id="@+id/home_video_layout"
   android:src="@drawable/splash_image"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:scaleType="centerCrop"
   />

Updated:更新:

Understanding Screen Densities and the “dp”了解屏幕密度和“dp”

Resolution is the actual number of pixels available in the display, density is how many pixels appear within a constant area of the display, and size is the amount of physical space available for displaying your interface.分辨率是显示器中可用的实际像素数,密度是显示器恒定区域内出现的像素数,尺寸是可用于显示界面的物理空间量。 These are interrelated: increase the resolution and density together, and size stays about the same.这些是相互关联的:一起增加分辨率和密度,大小保持不变。 This is why the 320x480 screen on a G1 and 480x800 screen on a Droid are both the same screen size: the 480x800 screen has more pixels, but it is also higher density.这就是为什么 G1 上的 320x480 屏幕和 Droid 上的 480x800 屏幕都是相同屏幕尺寸的原因:480x800 屏幕具有更多像素,但密度也更高。

To remove the size/density calculations from the picture, the Android framework works wherever possible in terms of "dp" units, which are corrected for density.为了从图片中删除大小/密度计算,Android 框架尽可能使用“dp”单位,这些单位已针对密度进行了校正。 In medium-density ("mdpi") screens, which correspond to the original Android phones, physical pixels are identical to dp's;在与原始 Android 手机相对应的中密度(“mdpi”)屏幕中,物理像素与 dp 相同; the devices' dimensions are 320x480 in either scale.设备的尺寸为 320x480 的任一比例。 A more recent phone might have physical-pixel dimensions of 480x800 but be a high-density device.较新的手机可能具有 480x800 的物理像素尺寸,但它是高密度设备。 The conversion factor from hdpi to mdpi in this case is 1.5, so for a developer's purposes, the device is 320x533 in dp's.在这种情况下,从 hdpi 到 mdpi 的转换系数是 1.5,因此出于开发人员的目的,设备的 dp 为 320x533。

I have found this online dip <--> pixels calculator very useful.我发现这个在线倾角 <--> 像素计算器非常有用。

https://pixplicity.com/dp-px-converter/ https://pixplicity.com/dp-px-converter/

我支持以前的答案,但不要忘记Draw9Patch的强大功能或使用NinePatchDrawables

These refer to screen pixel density , not screen dimension.这些是指屏幕像素密度,而不是屏幕尺寸。 You need to look into screen size specifiers like small, medium, large, and xlarge instead if you really need to change behavior based on screen size in pixels.如果您确实需要根据屏幕尺寸(以像素为单位)更改行为,则需要查看屏幕尺寸说明符,如小、中、大和 xlarge。

The Android docs explain what densities and sizes match these identifiers. Android 文档解释了与这些标识符匹配的密度和大小。

Android devices can have different width-to-height ratios, while your image has a fixed one. Android 设备可以具有不同的宽高比,而您的图像具有固定的宽高比。 If you do not want your image stretched, you will have to fill the blank spaces above and below or left and right.如果您不想拉伸图像,则必须填充上下或左右的空白区域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM