Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine device screen size category (small, normal, large, xlarge) using code?

Is there any way to determine the category of screen size of the current device, such as small, normal, large, xlarge?

Not the density, but the screen size.

like image 740
vieux Avatar asked Feb 16 '11 10:02

vieux


People also ask

Which are the screen size in Android small Large normal?

Screen-size Buckets Android has included support for three screen-size “buckets” since 1.6, based on these “dp” units: “normal” is currently the most popular device format (originally 320x480, more recently higher-density 480x800); “small” is for smaller screens, and “large” is for “substantially larger” screens.

What is considered a small screen device?

normal screens are at least ~2.9" x 2" small screens are at least ~2.7" x 2"


1 Answers

You can use the Configuration.screenLayout bitmask.

Example:

if ((getResources().getConfiguration().screenLayout &      Configuration.SCREENLAYOUT_SIZE_MASK) ==          Configuration.SCREENLAYOUT_SIZE_LARGE) {     // on a large screen device ...  } 
like image 181
Jeff Gilfelt Avatar answered Sep 21 '22 16:09

Jeff Gilfelt