Skip to content

Instantly share code, notes, and snippets.

@thoretton-edwin
Created July 11, 2014 14:32
Show Gist options
  • Save thoretton-edwin/19a48d49d37ef8039ad9 to your computer and use it in GitHub Desktop.
Save thoretton-edwin/19a48d49d37ef8039ad9 to your computer and use it in GitHub Desktop.
Android get screen size
int screenWidth = 0;
int screenHeight = 0;
if(android.os.Build.VERSION.SDK_INT < 10) {
Display display = getWindowManager().getDefaultDisplay();
screenWidth = display.getWidth();
screenHeight = display.getHeight();
} else {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
screenWidth = metrics.heightPixels;
screenHeight = metrics.widthPixels;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment