如何在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
相关文章
相关标签/搜索