简体   繁体   English

具有相同分辨率的设备上的Android DPI独立性

[英]Android DPI independence on devices with same the resolution

I Have a few general questions about Android screen / DPI / resolution indepence. 我对Android屏幕/ DPI /分辨率独立性有一些一般性问题。

Basically, I am taking specifically about sprite-based apps, like ones based on Surfaceview for example. 基本上,我主要讲的是基于Sprite的应用程序,例如基于Surfaceview的应用程序。

Every guide I've read (including the official one) says that you should only work with the DPI and not the resolution. 我读过的每本指南(包括官方指南)都说,您仅应使用DPI,而不应使用分辨率。

However, what happens when two devices have different DPI's/screen size but the same resolution? 但是,当两个设备的DPI /屏幕尺寸不同但分辨率相同时,会发生什么情况? Take the Galaxy tab 10.1 (1280 x 800 - DPI aprox 150) and the Galaxy Note (1280 x 800 aprox 285 DPI I think??) 拿Galaxy Tab 10.1(1280 x 800-DPI aprox 150)和Galaxy Note(1280 x 800 aprox 285 DPI我认为??)

When displaying a sprite of say 50 x 50 on each of these, it will appear to be the same size relative to the screen size. 当在每个屏幕上显示例如50 x 50的精灵时,相对于屏幕尺寸,它的大小似乎相同。 However, if Android grabs a difference size sprite because it detects a different DPI (ie, from LDPI, HDPI etc), then the sprite will appear to be bigger on the Note relative to the screen size than it would on the Tab. 但是,如果Android由于检测到不同的DPI(例如,来自LDPI,HDPI等)而捕获大小不同的Sprite,则相对于屏幕大小,Note上的Sprite看起来会比Tab上的Sprite大。

Can anyone please set me straight on this as I just cannot work it out!! 任何人都可以请我直接解决这个问题,因为我无法解决!! Thanks all. 谢谢大家

A 50 x 50 sprite on a 150dpi screen will appear much larger than a 50 x 50 sprite on a 285dpi screen. 在150dpi屏幕上显示50 x 50的精灵比在285dpi屏幕上显示50 x 50的精灵大得多。 Android's resource resolution algorithm is intended to allow you to define a larger (in pixels) image for use on higher density screens. Android的资源解析算法旨在允许您定义较大(以像素为单位)的图像,以用于更高密度的屏幕。

If you want the sprite to be the same size relative to the screen regardless of the pixel density, then you can put the images in the drawable-nodpi folder and they won't be scaled by the system. 如果您希望精灵相对于屏幕具有相同的大小,而不管像素密度如何,则可以将图像drawable-nodpi文件夹中,并且系统不会缩放它们。 You can even decide which size image to use in code after querying the screen size. 查询屏幕尺寸后,您甚至可以决定在代码中使用哪种尺寸的图像。 (As of 3.2, you can have resource folders that depend on screen pixel size, but I think they will still scale with dpi.) (从3.2版本开始,您可以拥有取决于屏幕像素大小的资源文件夹,但我认为它们仍会随着dpi缩放。)

Screen resolution refers to the screen dimension in pixels. 屏幕分辨率是指屏幕尺寸(以像素为单位)。 Pixel density refers to how many pixels it takes to fill an inch of screen. 像素密度是指填满一英寸的屏幕需要多少像素。

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

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