Vlad Vlad - 18 days ago 12
Android Question

Nexus 7 actual screen size

I built a simple application for Nexus 7. I used the following code to get the screen size in DP units.

this.getResources().getConfiguration().screenWidthDp;
this.getResources().getConfiguration().screenHeightDp;


where "this" is MainActivity context object.

I get these values: 600 dp for width and 888 dp for height.

Pixel density is
tvdpi
which is 213, and the ratio of dp to pixels is 1.33

I used this formula

pixels = dips * (density / 160)


which gives me for height

pixels = 888 * (213 / 160) = 1182.15.


I know that pixel size of the Nexus 7 screen is 800 x 1280. Where are the missing 100 pixels of height in this calculation? Or did I do something wrong?

Answer

Configuration.screenHeightDp() returns the dimensions of the available area of the screen.

Your calculated value, 1182, is close to the the height in pixels minus the navigation bar and status bar (1173) of the Nexus 7, in other words the resolution available for your app to use.

Full screen apps should be able to use the full 1280 resolution.

Comments