如何获得Android的屏幕尺寸,包括虚拟按钮? [英] How to get screen size in Android, including virtual buttons?

查看:372
本文介绍了如何获得Android的屏幕尺寸,包括虚拟按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关使用正常,你可以使用DisplayMetrics类,并获得了渲染的大小,但我想弄清楚的实际物理屏幕尺寸,其中包括虚拟按键的高度。

在我的Galaxy Nexus报告的大小无论我试过是1196x720,我可以用它来获得物理其中一个为1280x720?也是一样的Nexus 7和Nexus 4和Nexus 10的设备。

更新:这是最后的code我现在用的,包括修复:

  //活动A =这一点;
    DisplayMetrics displayMetrics =新DisplayMetrics();
    窗口管理WM =(窗口管理器)A.getApplicationContext()getSystemService(Context.WINDOW_SERVICE)。
    显示DISP = wm.getDefaultDisplay();    INT API_LEVEL = android.os.Build.VERSION.SDK_INT;
    如果(API_LEVEL> = 17)
    {
        disp.getRealMetrics(displayMetrics);
    }
    其他
    {
        disp.getMetrics(displayMetrics);
    }    INT宽度= displayMetrics.widthPixels;
    INT身高= displayMetrics.heightPixels;


解决方案

您应该使用<一个href=\"https://developer.android.com/reference/android/view/Display.html#getRealSize%28android.graphics.Point%29\"相对=nofollow> Display.getRealSize(点)从官方文档的这里


  

显示区域以两种不同的方式描述


  
  

的应用程序显示区域指定显示器的一部分
  可能包含一个应用程序窗口,但不包括在系统的装饰品。


  
  

的应用程序显示区域可以比真实的显示区域更小的
  因为系统中减去所需的装饰元素,例如该空间
  为状态栏。使用下列方法来查询应用
  展示区:的getSize(点),getRectSize(矩形),并
  getMetrics(DisplayMetrics)。


  
  

真正的显示区域指定部分
  中包含的内容包括系统的装饰显示器。
  即使如此,在实际显示区域可能会比实际尺寸小
  显示器如果窗口管理器模拟一个较小的显示器
  使用(ADB壳上午显示屏大小)。使用以下方法来查询
  真正的显示区:getRealSize(点),
  getRealMetrics(DisplayMetrics)。


For normal uses you can use the DisplayMetrics class and get the "renderable" size, but I want to figure out the actual physical screen size, which includes the virtual buttons height.

On my Galaxy Nexus the reported size no matter what I tried is 1196x720, what can I use to get the physical one which is 1280x720 ? Same goes for Nexus 7, Nexus 4 and Nexus 10 devices.

UPDATE : This is the final code I now use, including the fix :

    //Activity A = this;
    DisplayMetrics displayMetrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) A.getApplicationContext().getSystemService(Context.WINDOW_SERVICE); 
    Display disp = wm.getDefaultDisplay();

    int API_LEVEL =  android.os.Build.VERSION.SDK_INT;
    if (API_LEVEL >= 17)
    {
        disp.getRealMetrics(displayMetrics);
    }
    else
    {
        disp.getMetrics(displayMetrics);
    }

    int Width = displayMetrics.widthPixels;
    int Height = displayMetrics.heightPixels;

解决方案

You should use Display.getRealSize(Point) From the official docs here

The display area is described in two different ways.

The application display area specifies the part of the display that may contain an application window, excluding the system decorations.

The application display area may be smaller than the real display area because the system subtracts the space needed for decor elements such as the status bar. Use the following methods to query the application display area: getSize(Point), getRectSize(Rect) and getMetrics(DisplayMetrics).

The real display area specifies the part of the display that contains content including the system decorations. Even so, the real display area may be smaller than the physical size of the display if the window manager is emulating a smaller display using (adb shell am display-size). Use the following methods to query the real display area: getRealSize(Point), getRealMetrics(DisplayMetrics).

这篇关于如何获得Android的屏幕尺寸,包括虚拟按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆