通过Supporting Different Densities,有4种类型的屏幕:
xhdpi
hdpi
mdpi
ldpi
我想知道这些是什么样的屏幕大小(在PIXEL中)? :
normal-xhdpi large-xhdpi
normal-hdpi large-hdpi
normal-mdpi large-mdpi
这些屏幕尺寸由Eclipse提供:
xhdpi : 768 x 1280
2560 x 1600
720 x 1280
hdpi : 480 x 800
480 x 854
mdpi : 1280 x 800
1024 x 600
480 x 854
480 x 800
320 x 480
答案 0 :(得分:2)
看到你正在混合这些概念。小,中,大和xlarge是屏幕尺寸,而ldpi,mdpi,hdpi,xhdpi,nodpi和tvdpi是屏幕密度
<强>尺寸强>
small - Resources for small size screens.
normal - Resources for normal size screens. (This is the baseline size.)
large - Resources for large size screens.
xlarge - Resources for extra large size screens.
<强>密度强>
ldpi Resources for low-density (ldpi) screens (~120dpi).
mdpi Resources for medium-density (mdpi) screens (~160dpi).
(This is the baseline density.)
hdpi Resources for high-density (hdpi) screens (~240dpi).
xhdpi Resources for extra high-density (xhdpi) screens (~320dpi).
nodpi Resources for all densities. These are density-independent resources.
The system does not scale resources tagged with this qualifier,
regardless of the current screen's density.
tvdpi Resources for screens somewhere between mdpi and hdpi; approximately
213dpi. This is not considered a "primary" density group. It is mostly
intended for televisions and most apps shouldn't need it—providing mdpi and
hdpi resources is sufficient for most apps and the system will scale them as
appropriate. If you find it necessary to provide tvdpi resources,
you should size them at a factor of 1.33*mdpi.
For example, a 100px x 100px image for mdpi screens should be 133px x 133px for tvdpi.
现在,每种尺寸的最小分辨率定义如下
xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
同样来自android Docs
dp单位到屏幕像素的转换很简单:像素= dps *(密度/ 160)。例如,在240 dpi屏幕上,1 dp将等于1.5个物理像素。强烈建议使用dp单位来定义应用程序的UI,以确保在不同屏幕上正确显示UI。
这意味着具有不同密度的两个不同设备可以具有相同数量的dp但不具有相同的像素。
答案 1 :(得分:1)
此公式适用于我获取屏幕大小并将其转换为像素:
float scale = getBaseContext().getResources().getDisplayMetrics().density;
int pixels = (int) (120 * scale + 0.5f);