Android的:如何获得设备的实际屏幕尺寸? [英] Android: How to get the real screen size of the device?

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

问题描述

我曾尝试不同的方式来获得设备的屏幕尺寸,但它总是返回我错了尺寸(791x480,而不是854×480),这可能是由于导航栏。我的设备正在运行软糖4.1.1。

I have tried different ways to get the screen size of the device, but it always returned me the wrong size (791x480 instead of 854x480), it might be due to the navigation bar. My device is currently running JellyBean 4.1.1.

我想:

Display display = getWindowManager().getDefaultDisplay();  
Point size = new Point();
display.getSize(size);
OpenGLRenderer.widthScreen = size.x;
OpenGLRenderer.heightScreen = size.y;

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
String resolution = dm.widthPixels + "x" + dm.heightPixels;

我用下面的code,使应用程序全屏:

I'm using the following code to make the app full screen:

setContentView(mGLSurfaceView);
mGLSurfaceView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

我注意到,在logcat的大小合适,则返回:

I noticed that in the logcat the right size is returned :

01-01 03:05:06.967: I/InputReader(1961): 
    Device reconfigured: id=8, name='cyttsp-spi', 
    surface size is now 480x854, mode is 1

在我AndroidManifest:

In my AndroidManifest :

uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16"

我用:

  • Get the real screen resolution on Ice Cream Sandwich
  • HTC Sensation Real Resolution
  • Android: How to get screen dimensions

为什么我不能够得到真正的大小(的480x854 )?或者,我怎么可以使用由重新配置设备返回地面?

Why am I not able to get the real size (480x854) ? Or how can I use the surface returned by the "Device reconfigured" ?

推荐答案

尝试调用

    display.getRealSize();

免责声明: 我没有意识到这一点,但是这将仅适用于API 17(安卓4.2 /软糖)及以上。

DISCLAIMER: I did not realize this, but this will only work for API 17 (Android 4.2/JellyBean) and up.

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

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