Android的图像,密度和屏幕像素 [英] Android images, density, and screen pixels

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

问题描述

我对Android文档困惑这个问题,所以我会在这里问他们:
我有这个链路上的HTC Desire手机我看到它的像素为480×800和252的密度


  1. 当我试图让密度这样的getResources()。getDisplayMetrics()。densityDpi我得到值240,而不是252。

  2. 我的图像大小为400x113与密度240(像素/英寸),当我尝试的getWidth获得程序的大小和getHeight它说600和170。

  3. 什么大小我的形象,需要为这款手机的HTC Desire和密度它需要有。

感谢。


解决方案

  1. Android的设备投入到水桶:LDPI,MDPI,华电国际,xhdpi。欲望落入华电国际桶是240dpi。正如你所看到的,252dpi非常接近240dpi。

  2. 默认MDPI是160dpi。当获得资源,除非另行指定它会尝试规模从原来的密度图像到新的。 160:240 :: 400:600 :: 113:170。你可能把你的图像中绘制文件夹中。

  3. 此大小是好的,但你应该把它放在绘制,华电国际文件夹,如果它是华电国际的设备。 (你或许应该还放了MDPI版本适用于mdpi设备绘制,于mdpi文件夹适当大小的太)。

文件的详细信息,支持对密度多屏幕和信息

I am confused by Android documentation about this questions so I will ask them here: I have HTC Desire mobile on this link I see that it has pixels 480×800 and Density 252

  1. When I try to get Density like this getResources().getDisplayMetrics().densityDpi I get value 240 and not 252.
  2. I have image with size 400x113 with Density 240(Pixels/Inch) And when I try to get size in program with getWidth and getHeight it said 600 and 170.
  3. What size my image need to be for this phone HTC Desire and which Density it need to have.

Thanks.

解决方案

  1. Android puts devices into buckets: ldpi, mdpi, hdpi, xhdpi. The Desire falls into the hdpi bucket which is 240dpi. As you can see, 252dpi is very close to 240dpi.
  2. The default mdpi is 160dpi. When getting resources, unless you specify otherwise it will try to scale images from the original density to the new one. 160:240::400:600::113:170. You probably put your image in the drawable folder.
  3. This size is fine, but you should put it in the drawable-hdpi folder if it's for hdpi devices. (You should probably also put a mdpi version sized appropriately in the drawable-mdpi folder for mdpi devices too).

Read through this document for details on supporting multiple screens and information on densities.

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

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