---
title: "Android模拟器更改分辨率后 无法取得分辨率问题"
author: "sinfrancis"
date: "2011-05-11T21:06:24Z"
tags: ["Android", "Blog", "XML"]
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2011-05-11T21:12:59Z"
id: 1040662
url: "https://sinfrancis.iteye.com/blog/1040662"
---

在PC上更改模拟器分辨率为480\*800

（如果你的PC界面没有这么大，你可以在ADV Manager启动模拟器的时候设置一下缩放成真实的大小）

 

 

![](http://dl.iteye.com/upload/attachment/479531/25a8c44a-0d13-3aac-9516-e57ad0fe7f16.jpg)

 

 

但是代码中取得的分辨率却是 320 \*511，程序只能显示一部分。

 

可以在AndroidManifest.xml中配置一下代码：

 

```
    <supports-screens android:smallScreens="true" android:anyDensity="true" 
    android:largeScreens="true" android:normalScreens="true">
    </supports-screens>
    <uses-sdk android:minSdkVersion="3"></uses-sdk>
```

 

 

就能正确获得了。

 

 

但是获得的实际的高度了宽度

 

 

```
        TextView tv=(TextView)findViewById(R.id.tv);
        DisplayMetrics dm=new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        float width=dm.widthPixels*dm.density;
        float height=dm.heightPixels*dm.density;
        tv.setText(width+"X"+height);
```

 

如果density大于了1，模拟器的中的宽度和高度肯定会大于我们设置的480\*800。

 

真机上这样取得实际的高度和宽度还没试过，等试过之后再更改这篇BLOG。