In Android, we have different screen sizes depending on the devices so if we need to set width and height of components dynamically, we will need to know the current device’s screen dimension.
We do that by getting “Display” object from “Window Manager” so in current “Activity” class:
1 2 3 | Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); |
But the screen height is including the status bar on top so we need to deduct from it too and normally status bar has height of 25dp:
1 2 3 4 | Display display = getWindowManager().getDefaultDisplay(); int statusBarHeight = 25; int width = display.getWidth(); int height = display.getHeight() - statusBarHeight ; |
No user commented in " Android: Getting Screen Dimension "
Follow-up comment rss or Leave a TrackbackLeave A Reply