Android的多个屏幕大小有相同的密度 [英] Android multiple screen sizes with same density

查看:107
本文介绍了Android的多个屏幕大小有相同的密度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑就密度。我看到,中密度,屏幕分辨率可以是小320x480,480x800的,或为480x854。所以,如果我有这就是为300px宽中MDPI文件夹中的图像,它是如何去看看相同的大小在所有3个不同的屏幕尺寸(分辨率320x480主要是相较于其他2)? 并通过看相同的大小,我的意思是根据屏幕大小规模更大或更小。谢谢你。

I'm confused regarding the densities. I see that with medium density, the screen resolution could be either 320x480, 480x800, or 480x854. So if I have an image thats 300px wide in the mdpi folder, how is it going to look the same size on all 3 different screen sizes (mainly 320x480 vs the other 2)? And by look the same size, I mean scale to be bigger or smaller depending upon the screen size. Thanks.

推荐答案

有三个不同的,但挂的概念在这里明白了:屏幕像素密度(每英寸/厘米,或俗称DPI每英寸点数的打印机像素),物理屏幕尺寸(以英寸或厘米)和像素数(也称为分辨率,像素)。

There are three distinct but linked concepts to understand here: screen density (pixels per inch/centimeter, or commonly known as DPI from dots per inch in printers), physical screen size (in inches or centimeters) and number of pixels (also known as resolution, in pixels).

这些条款的没有的互换的,你需要了解他们是如何以相互连接起来不被这个问题困惑。通常情况下,你可以忽略物理屏幕大小,因为这已经占了密度。例如一个屏幕3英寸宽,300像素跨越将具有100。此外电话屏幕往往具有大约相同的物理尺寸一新闻部,即使像素的数量是非常不同的。

These terms are not interchangeable, and you need to understand how they interlink to not be confused with the issue. Generally, you can ignore physical screen size since that's already accounted for in the density. For example a screen 3 inches wide and 300 pixels across will have a DPI of 100. Furthermore phones screens tend to have about the same physical size, even if the number of pixels is very different.

那么,让我们来考虑一个G1或英雄具有分辨率480x320的分辨率和大约160dpi的密度的屏幕。图像300像素宽将1.875英寸跨越。这是由像素大小(300)/密度(160)来计算。现在,如果你比较这对的的Nexus One,Droid的或类似的屏幕,这些机型有大约800×480的有大约240dpi的高密度更高分辨率的屏幕。如果显示相同的300像素宽的图像,它现在只是身体将在大约一显示,四分之一英寸宽。换句话说,这将是小很多。这可能是一个问题,因为如果图像包含文本,则该文本可能无法读取了。

So, let's consider the screen of a G1 or Hero which has a resolution 480x320 and a density of approx 160dpi. An image 300 pixels wide will be 1.875 inches across. This is calculated by pixel size (300) / density (160). Now if you compare this to the screen of the Nexus One, Droid or similar, these models have a higher resolution screen of approx 800x480 with a high density of approx 240dpi. If you display the same 300px wide image, it will now only physically be displayed at about one and a quarter inches across. In other words, it will be much smaller. This can be a problem because if the image contains text, then the text might not be readable anymore.

机器人可以被告知自动缩放图像,以适应这些不同的屏幕,以便它仍然看起来是相同的大小。这是通过设置大小的密度独立的像素进行。如果事情是100dp宽,这将是100像素宽的中密度屏幕上。在高密度的屏幕,这将是150像素宽,但他们看起来都差不多大的实际屏幕上。但是,如果你这样做,你的形象可以去有点模糊。这是同样的,当你放大成照片过于密切的图片查看程序的;边缘去模糊的,因为它'延伸'他们,而你放大。

Android can be told to automatically scale images to fit these different screens so that it still looks to be the same size. This is done by setting sizes in Density Independent pixels. If something is 100dp wide, it will be 100px wide on a medium density screen. On a high density screen, it will be 150px wide, but they will both look about the same size on the actual screen. However, if you do this, your image can go a bit blurry. It's the same as when you zoom into a photo too closely in a picture viewing program; the edges go blurry since it 'stretches' them while you zoom.

要解决这个问题的方法是使用MDPI,HDPI等的文件夹。你给机器人已被缩放,以便它没有这样做本身的图像。显然,如果你只是你自己伸展的形象在Photoshop中,那么就不会看任何好转。但通常一个是调整图像非常大降,使他们适应手机屏幕。在这种情况下,你只要调整它们的大小三个不同的时间,每到一个不同的分辨率。

The way to solve this is to use the mdpi, hdpi and so forth folders. You're giving Android an image that has already been scaled, so that it doesn't have to do it itself. Obviously if you just stretch the image yourself in Photoshop, then it won't look any better. But normally one is resizing very large images down to make them fit the mobile screen. In that case, you just resize them three different times, each into a different resolution.

所以到最后回答您的具体问题:如果你有放置在MDPI文件夹中的图像,这将是完全一样的大小,而不管屏幕分辨率,只要他们都是一样的密度。什么将改变是多大的空间周围,如一个320x320px宽的图像将填补一个最大分辨率320x480屏幕,但只有约480×800屏幕的三分之一。然而,如上所述,通常的更高的分辨率手机也具有更致密的屏幕。在这种情况下,Android将不会看着你的MDPI文件夹中的形象 - 它会去到华电国际的文件夹,如果它不能找到它,它会采取默认的绘制文件夹中。然后,如果你已经使用DP它会自动缩放,或者如果你已经使用PX,它会离开它是,它只是看起来更小。

So to finally answer your specific question: if you have an image placed in your mdpi folder, it will be exactly the same size regardless of the screen resolution, as long as they are all the same density. What will change is how much space around them, e.g. a 320x320px wide image would fill most of a 320x480 screen, but only about a third of a 480x800 screen. However, as noted above, generally the higher resolution phones also have a more dense screen. In that case, Android won't look in your mdpi folder for the image - it will go to the hdpi folder, and if it can't find it there, it will take the default "drawable" folder. Then if you've used DP it will automatically scale it, or if you've used PX, it will leave it as is, and it will just look smaller.

在那里!一个很长的答案给你。我希望这是有道理的。

There! A very long answer for you. I hope it makes sense.

这篇关于Android的多个屏幕大小有相同的密度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆