Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

smallest width layouts. bug in Nexus 7?

When using the layout-swdp qualifiers I get the results as shown in the attachment. The sw qualifier is supposed to mean the smallest dimension must match or be bigger than the qualifier. This doesn't seem to work with the Nexus 7 (running 4.2.1). Am I confused about what smallest width qualifiers do or is the N7 reporting wrongly?

To reproduce my test case, I have many layout-swdp folders. Each has 2 textfield. The first just states which folders it's in. The next is the code below:

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;
}

enter image description here

like image 565
user123321 Avatar asked Oct 21 '22 18:10

user123321


1 Answers

Okay, this seems to be a bug in ICS where it doesn't accurate report the number of pixels of the entire screen as it taking into account the chrome.

Android DisplayMetrics returns incorrect screen size in pixels on ICS

So, my above display numbers are off as nexus 7 is 1280 x 800 and not 1280 x 736. Using the correct numbers, everything works.

like image 162
user123321 Avatar answered Nov 03 '22 23:11

user123321