这两天在调试开源桌面程序ADW的时候,发现此桌面程序按钮都很模糊,于是在打log查看其获取的屏幕分辨率:
Log.i("width000000", String.format("%d", getWindowManager().getDefaultDisplay().getWidth()));
Log.i("height0000000", String.format("%d", getWindowManager().getDefaultDisplay().getHeight()));
打印出来的结果是
05-29 06:46:46.336: I/width000000(2339): 320
05-29 06:46:46.347: I/height0000000(2339): 480
但手机是魅族的m9,其分辨率是 640*960。刚开始我怀疑是不是程序设置了分辨率限定,于是在AndroidManifest.xml中找,没找着。在程序中的不同位置打印log,显示的分辨率始终是320*480。
今天找到一篇文章,是跟程序分辨率支持有关的,不过是英文:
http://developer.android.com/guide/practices/screens-support-1.5.html
If your manifest file includes the <uses-sdk>
element, with theandroid:minSdkVersion
attribute set to "3"
or lower, and does notinclude the android:targetSdkVersion
set to "4"
or higher, then this document is for you. By default, an application written for Android 1.5 or below that does not set the android:targetSdkVersion
set to "4"
or higher runs in screen compatibility mode when on a device with a screen larger than the normal screen size (basically, the system displays the application in a small window that is roughly the size of the normal screen size).
用谷歌翻译了一下这段话,大致是说如果程序的manifest 中没有使用 <uses-sdk>这个标签或标签标签的sdk小于或等于3,系统就会默认一个正常大小的分辨率给程序。
这个默认分辨率是多少呢,根据dp的定义,应该是160/英寸,就是说魅族目前分辨率是330/英寸,那么程序默认分辨率就是320*480。这样就解决了疑问。
我在AndroidManifest.xml中增加
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
这个语句,显示果然正常。