android - 如何获取手机屏幕的高度和宽度

标签 android

我使用这段代码来查找屏幕的高度和宽度

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

但我得到 1080 x 1920 for samsung galaxy S4800 x 1280 for Nexus 7。但我实际上需要原始的高度和宽度。获取方式。

最佳答案

希望对你有帮助

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics); 
int screenHeight = metrics.heightPixels;
int screenWidth = metrics.widthPixels;
Log.i("MY", "Actual Screen Height = " + screenHeight + " Width = " + screenWidth);

关于android - 如何获取手机屏幕的高度和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22370554/

相关文章:

javascript - 传单不显示 map

android - Superpowered SDK : Error:Execution failed for task ':app:ndkBuild' . 启动进程 'command ' null/ndk-build''

android - 带有动态按钮android的扩展列表中的计时器

android - FaceBook ShareLinkContent setImageUrl 被 android 中的 ContentUrl 元数据取代

android - 我应该使用 MonoDroid 还是 Android?

java - 使用 GSON 解析 JSON 返回 null

android - 网页上的链接以打开 Instagram 应用程序

java.lang.IllegalArgumentException : Failed to read S3TransferUtility please check your setup or awsconfiguration. json 文件

Android:重置启动屏幕

android - Meteorjs - Android 应用程序包未正确签名错误