Problema con el cálculo de DP en tableta de 7 "y emulador de tableta de 7"

I am having some problems with the dp calculation for a 7" tablet (800x480px). Below is my way of calculating. Can't find where I am making a mistake in calculation or my thought:

I have three devices that I'm testing:

1. Nexus One: 800x480px, 3.7" display (especificaciones)
2. Huawei Ideos: 320x240px, 2.8" display (especificaciones)
3. Ainol Novo 7" Tablet: 800x480px, 7" display (especificaciones)

Based on the display size, I'm calculating the DPI (dots per inch) manually, based on the formular:

``````sqrt(w^2 + h^2) / in
``````

So I am getting:

1. Nexus One: sqrt(800*800+480*480)/3.7 = 252.15dpi
2. Huawei Ideos: sqrt(320*230+240*240)/2.8 = 142.86dpi
3. Ainol Novo 7" Tablet: sqrt(800*800+480*480)/7 = 133.28 dp

Now I want to output the dpi value of the screen metrics and based on that, the screen width and height in dp (density-independent pixels). My code for that is:

``````    DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Log.d(TAG, "ScaledDensity: " + metrics.scaledDensity);
Log.d(TAG, "Density DPI: " + metrics.densityDpi);

int widthInPx = 800; // 320 or 800, depending on the respective device width I'm testing
int widthInDp =(int)(widthInPx/metrics.scaledDensity);
Log.d(TAG, "width in dp: " + widthInDp);

int heightInPx = 480; // 240 or 480, depending on the respective device height I'm testing
int heightInDp =(int)(heightInPx/metrics.scaledDensity);
Log.d(TAG, "height in dp: " + heightInDp);
``````

1. Nexus One: Scaled Density: 1.5, Density DPI: 240, Width in dp: 533, Height in dp: 320
2. Huawei Ideos: ScaledDensity: 0.75, Density DPI: 120, width in dp: 426, height in dp: 320
3. Ainol Novo 7" tablet: ScaledDensity: 1.0, Density DPI: 160, width in dp: 800, height in dp: 480

The density DPIs that I get from the java code inside my activity differ from my calculated dpi values and are obviously rounded by Android to one of the values 120, 160 or 240, which is quite normal. No problem so far.

Problem/Question 1:

With the third device, the Novo 7" tablet: The ScaledDensity is said to be 1.0, and the width in dp is said to be 800, same as the number of px. However, that's not the reality; when I create a fullscreen app and place a view on there, only 533dp x 320dp of the view actually fit on the screen. So it's the same dp measurements as the Nexus One; even though the Nexus One has a higher DPI value but the same number of pixels. How is that possible?

Problem/Question 2:

I create an AVD for the emulator, with the exact measurements as the Novo 7" tablet. The log lines in my java code show the same values as for the real tablet device:

1. Ainol Novo 7" tablet Emulador: ScaledDensity: 1.0, Density DPI: 160, width in dp: 800, height in dp: 480

However, on the emulator, I can place a view with 580dp x 320 dp to to fully visible in a fullscreen activity. How is it possible that the width dp differs between the emulator and the real device with exact same measurements?

Problem/Question 3:

devices, here are some numbers for typical screen widths:

...

480dp: una tableta tweener como la Streak (480x800 mdpi).

600dp: una tableta de 7 ”(600x1024 mdpi).

...

I assume my tablet should fall under one of these categories, however, neither does it have 480 width nor 600 dp width, but something in between; in my case, either 533dp (real device) or 580dp (emulator).

If this is the case, what good does such a 'typical screen widths' overview do, if in reality, it doesn't actually seem to be the case but devices from different vendors can have any other random value in between the standard ones? Then I could just go ahead and back to working with pixel values again, as the entire benefit of using dp seems to be absent.

preguntado el 02 de febrero de 12 a las 11:02

1 Respuestas

Argh, I simply forgot the line

``````<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="11" />
``````

en mi manifiesto.

Without android:minSdkVersion, the are always problems; legacy issues with Android 1.5 I think.

Respondido 02 Feb 12, 16:02

I saw this question open and just wanted to add that the reason that the minSdkVersion becomes a problem when absent is because of Compatibility Mode. - Nick Campion

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.