5

使用 layout-swdp 限定符时,我得到的结果如附件所示。sw 限定符应该意味着最小维度必须匹配或大于限定符。这似乎不适用于 Nexus 7(运行 4.2.1)。我是否对最小宽度限定符的作用感到困惑,还是 N7 报告错误?

为了重现我的测试用例,我有许多 layout-swdp 文件夹。每个都有 2 个文本字段。第一个只是说明它所在的文件夹。接下来是下面的代码:

private CharSequence collectScreenStats() {
    StringBuilder str = new StringBuilder();
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    int width = metrics.widthPixels;
    int height = metrics.heightPixels;
    int dpWidth = (int)(width / metrics.density);
    int dpHeight = (int)(height / metrics.density);
    str.append(Build.MANUFACTURER);
    str.append(" ");
    str.append(Build.MODEL);
    str.append("\n");
    str.append("Pixels: ");
    str.append(width);
    str.append(" x " );
    str.append(height);
    str.append("\nDp (px / density): ");
    str.append(dpWidth);
    str.append("dp x " );
    str.append(dpHeight);
    str.append("dp" );
    str.append("\nsmallest w: " + Math.min(dpWidth, dpHeight));
    str.append("\ndensity: ");
    str.append(metrics.density);
    str.append("\ndensityDpi: ");
    str.append(metrics.densityDpi);

    return str;
}

在此处输入图像描述

4

1 回答 1

3

好的,这似乎是 ICS 中的一个错误,它不能准确报告整个屏幕的像素数,因为它考虑到了 chrome。

Android DisplayMetrics 在 ICS 上返回错误的屏幕尺寸(以像素为单位)

所以,我上面的显示数字是关闭的,因为 nexus 7 是 1280 x 800 而不是 1280 x 736。使用正确的数字,一切正常。

于 2013-01-31T01:45:24.053 回答