How to get screen width and height
问题 I tried to use following code to get screen width and height in android app development: Display display = getWindowManager().getDefaultDisplay(); int screenWidth = display.getWidth(); int screenHeight = display.getHeight(); but I got NullPointerException for my display , why? how to get screen width and height then? 回答1: If you're calling this outside of an Activity, you'll need to pass the context in (or get it through some other call). Then use that to get your display metrics: