Digital Propulsion

DIGITAL PROPULSION BLOG

Determining the devices screen size with Android

Posted by: Adam Plocher on January 03, 2008


When developing Android applications, you may sometimes need to modify the layout of your UI depending on the screen size of the device. Some UIs are ideal for horizontal screen sizes, while others are better for vertical. If you find yourself in need of the devices screen size, the following code should do the trick:


import android.util.DisplayMetrics;
...

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);

int height = dm.heightPixels;
int width = dm.widthPixels;



Comments temporarily disabled


W3C: XHTML 1.0 Transitional  W3C: CSS Validated