android中获取手机分辨率
来源:互联网 发布:劳拉西泮片 知乎 编辑:程序博客网 时间:2024/05/20 06:23
在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.)
Constants
public static final int DENSITY_DEFAULT
The reference density used throughout the system.
public static final int DENSITY_HIGH
Standard quantized DPI for high-density screens.
public static final int DENSITY_LOW
Standard quantized DPI for low-density screens.
public static final int DENSITY_MEDIUM
Standard quantized DPI for medium-density screens.
public static final int DENSITY_XHIGH
Standard quantized DPI for extra-high-density screens.
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 minSdkVersion
or targetSdkVersion
to "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中获取手机分辨率
- android中获取手机分辨率
- android中获取手机分辨率
- Android中获取手机的分辨率案例
- Android中怎样获取手机分辨率
- 获取Android手机分辨率
- android获取手机分辨率
- Android 获取手机分辨率
- android 获取手机分辨率错误
- Android 如何获取手机分辨率
- android 获取手机的分辨率
- android开发中获取手机分辨率大小的方法
- android中获取手机分辨率 device screen dimensions
- android 获取手机分辨率,手机高度宽度
- android 获取手机分辨率、状态栏、…
- 获取手机分辨率
- 获取手机分辨率
- DisplayMetrics 获取手机分辨率
- 俄罗斯方块88行 代码注释版 (一)
- try catch finally return 的执行顺序
- 自动发QQ消息脚本
- PKU3518 Prime Gap
- 1703 压力释放器
- android中获取手机分辨率
- Shell脚本修改crontab
- LPVOID
- ubuntu下利用dnw软件烧写OK6410开发板
- 1704 叠罗汉
- 107个常用javascript语句
- 俄罗斯方块88行 代码注释版 (二)
- boost::function和boost::bind
- 构建高性能服务(二)减小锁粒度 提高Java并发吞吐实例