安卓:显示错误的屏幕分辨率 [英] Android: Showing wrong screen resolution

查看:129
本文介绍了安卓:显示错误的屏幕分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Android手机的屏幕分辨率,使用这种code

I was trying to get the screen resolution of android phones,using this code

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

当我想这code在我的Galaxy S手机,我得到的屏幕分辨率为320x533像素,但在现实中的Galaxy S得到了480×800像素的屏幕分辨率。那么,什么是错的code ??

When i tried this code in my Galaxy S phone i got the screen resolution as 320x533 px, but in reality the Galaxy S got a screen resolution of 480x800 px. So what's wrong with the code??

我怎样才能获得特定设备的实际屏幕分辨率??

How can i get the actual screen resolution of a particular device??

推荐答案

最后,术后第2天搜索和测试,我终于设法找到了什么是真正的问题在这里.. 上述所有人员编码将给予正确的分辨率。但最重要的,这是我们必须要提到的manifest文件中目标SDK ..否则会给出错误的结果,如果密度大于1。

Finally after 2 days of searching and testing, i finally managed to find out what's the real issue here.. All those above coding will give correct resolution. But the most important this is that we need to mention the target SDK in the manifest file.. Otherwise it will give wrong result if the density is more than 1.

<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8" />

需要从4-9之间的任何设置targetSDK版本.. 希望这将有助于部分之一,未来面临着同样的问题。

need to set the targetSDK version from anything between 4-9.. Hope this will help some one in future facing the same issue.

这篇关于安卓:显示错误的屏幕分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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