Created
December 25, 2014 15:31
-
-
Save alxsimo/3e7871cd0f6541ab0dee to your computer and use it in GitHub Desktop.
[Android] Size and screen density
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void determineScreenDensity() { | |
| DisplayMetrics metrics = new DisplayMetrics(); | |
| getWindowManager().getDefaultDisplay().getMetrics(metrics); | |
| int density = metrics.densityDpi; | |
| if (density==DisplayMetrics.DENSITY_HIGH) { | |
| Toast.makeText(this, "DENSITY_HIGH: " + String.valueOf(density), Toast.LENGTH_LONG).show(); | |
| } | |
| else if (density==DisplayMetrics.DENSITY_MEDIUM) { | |
| Toast.makeText(this, "DENSITY_MEDIUM: " + String.valueOf(density), Toast.LENGTH_LONG).show(); | |
| } | |
| else if (density==DisplayMetrics.DENSITY_LOW) { | |
| Toast.makeText(this, "DENSITY_LOW:" + String.valueOf(density), Toast.LENGTH_LONG).show(); | |
| } | |
| else { | |
| Toast.makeText(this, "Density is neither HIGH, MEDIUM OR LOW: " + String.valueOf(density), Toast.LENGTH_LONG).show(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void determineScreenSize() { | |
| if((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) { | |
| Toast.makeText(this, "Large screen",Toast.LENGTH_LONG).show(); | |
| }else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) { | |
| Toast.makeText(this, "Normal sized screen" , Toast.LENGTH_LONG).show(); | |
| }else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) { | |
| Toast.makeText(this, "Small sized screen" , Toast.LENGTH_LONG).show(); | |
| }else { | |
| Toast.makeText(this, "Screen size is neither large, normal or small" , Toast.LENGTH_LONG).show(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment