如何在Android中以像素为单位获取屏幕尺寸 - How to get screen dimensions as pixels in Android

08/05 05:59
阅读数 61

问题:

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


解决方案:

参考一: https://stackoom.com/question/4GXY/如何在Android中以像素为单位获取屏幕尺寸
参考二: https://oldbug.net/q/4GXY/How-to-get-screen-dimensions-as-pixels-in-Android
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
在线直播报名
返回顶部
顶部