我怎样才能得到实际的屏幕高度? [英] How can I get the actual screen height?

查看:146
本文介绍了我怎样才能得到实际的屏幕高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让屏幕高度,这是

I'm trying to get the screen height, which is the

    DeviceScreenHeight - NavigationBarHeight - TitleBarHeight

下面总是code给我752,但真正的屏幕高度为800。

The code below always give me a 752, but the real screen height is 800.

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    mHeight = metrics.heightPixels;

如果我用onLayoutChange()来得到一个垂直match_parent视图的高度,高度为696。这是我所需要的值。

And if I use onLayoutChange() to get the height of a vertically "match_parent" view, the height is 696. This is the value I need.

但我想知道如何动态获取这个值,所以我可以在不同设备上适当的高度。

But I want to know how to get this value dynamically so I can get the proper "height" on different devices.

推荐答案

尝试

mWinMgr = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
int displayHeight = mWinMgr.getDefaultDisplay().getHeight();

,其中上下文语境实例。

where context is Context instance.

这篇关于我怎样才能得到实际的屏幕高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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