Skip to content

Instantly share code, notes, and snippets.

@vincent1086
Created March 16, 2017 06:48
Show Gist options
  • Save vincent1086/169ad410de496dabfe475722a5b380c5 to your computer and use it in GitHub Desktop.
Save vincent1086/169ad410de496dabfe475722a5b380c5 to your computer and use it in GitHub Desktop.
Android - get screen size
WindowManager wm = (WindowManager) textView.getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2){
Point size = new Point();
display.getSize(size);
deviceWidth = size.x;
} else {
deviceWidth = display.getWidth();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment