How to get screen dimensions as pixels in Android
问题 I created some custom elements, and I want to programmatically place them to the upper right corner ( n pixels from the top edge and m pixels from the right edge). Therefore I need to get the screen width and screen height and then set position: int px = screenWidth - m; int py = screenHeight - n; How do I get screenWidth and screenHeight in the main Activity? 回答1: If you want the display dimensions in pixels you can use getSize: Display display = getWindowManager().getDefaultDisplay(); Point