如何在Android中以像素爲單位獲取屏幕尺寸 - 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). 我建立了一些自定義元素,我想以編程方式將它們放置在右上角(頂部邊緣n像素,右側邊緣m像素)。 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? 如何在主活動中獲取screenWidthscreenHeight spa


解決方案:

參考一: https://stackoom.com/question/4GXY/如何在Android中以像素爲單位獲取屏幕尺寸
參考二: https://oldbug.net/q/4GXY/How-to-get-screen-dimensions-as-pixels-in-Android
相關文章
相關標籤/搜索