最小宽度布局.Nexus 7中的错误?

use*_*321 5 android android-layout

使用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;
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

use*_*321 3

好吧,这似乎是 ICS 中的一个错误,它在考虑镶边时无法准确报告整个屏幕的像素数。

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

因此,我的上述显示数字已关闭,因为 Nexus 7 是 1280 x 800,而不是 1280 x 736。使用正确的数字,一切正常。