android中获取手机分辨率
2012-07-06 11:07
274 查看
在Activity中
// ME722 测试 480*854 竖屏
Display display = this.getWindowManager().getDefaultDisplay();
int nHeight = display.getHeight(); //569
int nWidth = display.getWidth(); //320
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics( metrics );
int nDeviceHeight = (int)(metrics.heightPixels * metrics.density); // 569 * 1.5 = 853.5
int nDeviceWidth = (int)(metrics.widthPixels * metrics.density); // 320 * 1.5 = 480
float fPhisycalHeight = metrics.heightPixels * metrics.density / metrics.densityDpi; // 3.55625
float fPhisycalWidth = metrics.widthPixels * metrics.density / metrics.densityDpi; // 2.0
在AndroidManifest.xml中添加 <supports-screens android:anyDensity="true"/> 之后
或者是添加<uses-sdk android:minSdkVersion="4" /> 之后(最小版本号是4以及以上)
Display display = this.getWindowManager().getDefaultDisplay();
int nHeight = display.getHeight(); //854
int nWidth = display.getWidth(); //480
display.getMetrics( metrics );
metrics.heightPixels 854
metrics.widthPixels 480
metrics.density 1.5
多看Dev Guide
Lets you specify the screen dimensions the application supports. By default, a modern application (using API Level
4 or higher) supports all screen sizes; older applications are assumed to support only the "normal" screen size. Screen size is determined as the available pixels to an application after density scaling has been applied. (Note that screen size is a separate
axis from screen density.)
Since: API Level 4
The reference density used throughout the system.
Constant Value: 160 (0x000000a0)
Since: API Level 4
Standard quantized DPI for high-density screens.
Constant Value: 240 (0x000000f0)
Since: API Level 4
Standard quantized DPI for low-density screens.
Constant Value: 120 (0x00000078)
Since: API Level 4
Standard quantized DPI for medium-density screens.
Constant Value: 160 (0x000000a0)
Since: API Level 9
Standard quantized DPI for extra-high-density screens.
Constant Value: 320 (0x00000140)
An application "supports" a given screen size if it fills the entire screen and works as expected. By default, the system will resize your application
to fill the screen, if you have set either
higher. Resizing works well for most applications and you don't have to do any extra work to make your application work on larger screens.
// ME722 测试 480*854 竖屏
Display display = this.getWindowManager().getDefaultDisplay();
int nHeight = display.getHeight(); //569
int nWidth = display.getWidth(); //320
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics( metrics );
int nDeviceHeight = (int)(metrics.heightPixels * metrics.density); // 569 * 1.5 = 853.5
int nDeviceWidth = (int)(metrics.widthPixels * metrics.density); // 320 * 1.5 = 480
float fPhisycalHeight = metrics.heightPixels * metrics.density / metrics.densityDpi; // 3.55625
float fPhisycalWidth = metrics.widthPixels * metrics.density / metrics.densityDpi; // 2.0
在AndroidManifest.xml中添加 <supports-screens android:anyDensity="true"/> 之后
或者是添加<uses-sdk android:minSdkVersion="4" /> 之后(最小版本号是4以及以上)
Display display = this.getWindowManager().getDefaultDisplay();
int nHeight = display.getHeight(); //854
int nWidth = display.getWidth(); //480
display.getMetrics( metrics );
metrics.heightPixels 854
metrics.widthPixels 480
metrics.density 1.5
多看Dev Guide
Lets you specify the screen dimensions the application supports. By default, a modern application (using API Level
4 or higher) supports all screen sizes; older applications are assumed to support only the "normal" screen size. Screen size is determined as the available pixels to an application after density scaling has been applied. (Note that screen size is a separate
axis from screen density.)
Constants
public static final int DENSITY_DEFAULT
Since: API Level 4The reference density used throughout the system.
Constant Value: 160 (0x000000a0)
public static final int DENSITY_HIGH
Since: API Level 4Standard quantized DPI for high-density screens.
Constant Value: 240 (0x000000f0)
public static final int DENSITY_LOW
Since: API Level 4Standard quantized DPI for low-density screens.
Constant Value: 120 (0x00000078)
public static final int DENSITY_MEDIUM
Since: API Level 4Standard quantized DPI for medium-density screens.
Constant Value: 160 (0x000000a0)
public static final int DENSITY_XHIGH
Since: API Level 9Standard quantized DPI for extra-high-density screens.
Constant Value: 320 (0x00000140)
An application "supports" a given screen size if it fills the entire screen and works as expected. By default, the system will resize your application
to fill the screen, if you have set either
minSdkVersionor
targetSdkVersionto
"4"or
higher. Resizing works well for most applications and you don't have to do any extra work to make your application work on larger screens.
相关文章推荐
- android 获取手机屏幕分辨率和setRequestedOrientation设置屏幕方向
- android中获取手机分辨率
- 手机分辨率Android教程(十二)-- 使用DisplayMetrics获取手机分辨率
- Android 获取手机分辨率
- 获取Android手机的分辨率通过ADB命令
- [置顶] 获取android手机的屏幕分辨率 android开发
- android获取手机分辨率
- Android中DisplayMetrics 获取手机屏幕分辨率
- Android使用Displaymetrics类获取一下手机屏幕中的一些信息,获取屏幕分辨率
- Android手机获取屏幕分辨率
- android获取手机屏幕分辨率
- Android获取手机分辨率 和屏幕的方向
- android中获取手机分辨率
- Android 创建菜单项Menu及获取手机分辨率
- 获取android手机分辨率及相应的处理方式
- 获取Android手机分辨率
- 【小功能2】android获取手机信息(号码,内存,CPU,分辨率,MAC,IP,SD卡,IMEI,经纬度,信号强度等等)
- Android 创建菜单项Menu及获取手机分辨率
- android 获取手机的分辨率
- android手机屏幕分辨率获取异常