如何获得在Android的蜂巢屏幕分辨率? [英] How to get screen resolution in Android Honeycomb?

查看:124
本文介绍了如何获得在Android的蜂巢屏幕分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android蜂窝屏幕的实际分辨率。

I want to get real resolution of screen on Android Honeycomb.

下面是我的code

Display display = getWindowManager().getDefaultDisplay();
int w = display.getWidth();
int h = display.getHeight();

我的设备是华硕变压器TF101与大小是1280×800。

My device is Asus Transformer TF101 with size are 1280x800.

但上面的code使W = 1280和h = 752(我要的是800不是752)。

But above code make w = 1280 and h = 752 (That i want is 800 not 752).

我知道H< 800,因为它减去状态栏。

I know h < 800 because it's subtracted for status bar.

有什么办法让屏幕的实际高度是多少?

Have any way to get real height of screen?

非常感谢!

推荐答案

开始的Andorid 3.2,系统状态栏的高度不包括在DisplayMetrics的高度,你必须使用无证的API(Display.getRawWidth()和Display.getRawHeight ())来获得物理屏幕宽度或高度。

Starting Andorid 3.2, the height of system status bar is not included in DisplayMetrics's height, you have to use undocumented APIs (Display.getRawWidth() and Display.getRawHeight()) to get the physical screen width or height.

下面的例子向您展示如何获得物理屏幕宽度或高度。

Here is the example to show you how to get the physical screen width or height.

Method mGetRawW = Display.class.getMethod("getRawWidth");
Method mGetRawH = Display.class.getMethod("getRawHeight");
int nW = (Integer)mGetRawW.invoke(dp);
int nH = (Integer)mGetRawH.invoke(dp);

更新: 对于API 13-16,你必须使用上述code,以获得真正的宽度/高度。 对于API 17+,你现在可以使用新的公共API,Display.getRealSize()。

UPDATED: For API 13-16, you have to use the above code to get real width/height. For API 17+, you can now use the new public API, Display.getRealSize().

这篇关于如何获得在Android的蜂巢屏幕分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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