Android的DisplayMetrics返回不正确的屏幕大小以像素为单位的ICS [英] Android DisplayMetrics returns incorrect screen size in pixels on ICS

查看:181
本文介绍了Android的DisplayMetrics返回不正确的屏幕大小以像素为单位的ICS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经试过这....

I've tried this....

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int fullscreenheight = metrics.heightPixels;
int fullscreenwidth = metrics.widthPixels;

和......

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

该GNEX具有720×1280的显示。返回的结果宽/高(根据课程的方向)从来都不是1280.我​​想这可能有一些做与冰淇淋三明治屏幕上的导航栏,所以我隐藏搭配:

The Gnex has a display of 720×1280. The returned result for width/height (depending on orientation of course) is never 1280. I thought this might have something to do with the on screen navigation bar in Ice Cream Sandwich, so I hide that with :

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

...然后启动一个线程,它连续地记录屏幕尺寸高度/宽度。即使在ICS导航栏完全消失....屏幕尺寸绝不会报告1280值。我会得到的数字是这样的:

...and then started a thread which continuously logs the screen size height/width. Even after the ICS navigation bar was completely gone....the screen size would never report the 1280 value. I would get numbers like this:

width  = 720
height = 1184

你如何获得真正的设备屏幕分辨率ICS?

How do you get the true device screen resolution in ICS?

我之所以需要这个值是因为我的应用程序播放视频和我想的视频占用整个屏幕时,该设备为横向。现在我知道你在想什么,为什么不给videoviewmatch_parent的高度/宽度值?究其原因是因为我的影片有多种纵横比,我想能够计算出正确的视频的大小取决于屏幕的整个宽度。

The reason why I need this value is because my app plays video and I would like for the video to take up the entire screen when the device is in landscape orientation. Now I know what you're thinking, why not just give the videoview a value of "match_parent" for the height/width? The reason is because my videos have multiple aspect ratios and I'd like to be able to calculate the correct video size depending on the entire width of the screen.

推荐答案

我发现这个宝藏的ICS ONLY ......如果您定位的API高于ICS见注释通过以下克里斯Schmich。

I found this hidden treasure for ICS ONLY......if you're targeting API's higher than ICS see the comment by Chris Schmich below.

如何隐藏和显示在导航栏上的Andr​​oid ICS建立

在情况下,链接死....这里是如何得到实际的设备屏幕尺寸......

In case the link dies....here's how to get the actual device screen size.....

Display display = getWindowManager().getDefaultDisplay();     
Method mGetRawH = Display.class.getMethod("getRawHeight");
Method mGetRawW = Display.class.getMethod("getRawWidth");
int rawWidth = (Integer) mGetRawW.invoke(display);
int rawHeight = (Integer) mGetRawH.invoke(display);

修改(12年11月19日)

EDIT (11/19/12)

以上code将无法工作在Android 4.2和一个异常将被抛出....我还没有找到一种方式来获得设备的全屏幕大小的Andr​​oid 4.2。当我这样做,我会编辑这个答案,但现在,你应该code与应变为Android 4.2 !!

The above code WILL NOT WORK on Android 4.2 and an exception will be thrown....I have yet to find a way to get the full screen size of a device in Android 4.2. When I do, I will edit this answer, but for now, you should code with contingency for android 4.2!!

这篇关于Android的DisplayMetrics返回不正确的屏幕大小以像素为单位的ICS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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