android 获取屏幕分辨率_安卓系统分辨率设置
在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
Since: API Level 4
The reference density used throughout the system.
Constant Value: 160 (0x000000a0)
public static final int DENSITY_HIGH
Since: API Level 4
Standard quantized DPI for high-density screens.
Constant Value: 240 (0x000000f0)
public static final int DENSITY_LOW
Since: API Level 4
Standard quantized DPI for low-density screens.
Constant Value: 120 (0x00000078)
public static final int DENSITY_MEDIUM
Since: API Level 4
Standard quantized DPI for medium-density screens.
Constant Value: 160 (0x000000a0)
public static final int DENSITY_XHIGH
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 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.
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/170370.html原文链接:https://javaforall.cn
相关文章
- android onresume函数,Android界面跳转时候onDestroy和onResume的调用顺序
- 74款android开机动画,修改Android系统开机动画
- android更换开机动画,修改安卓开机动画(除了部分系统 如MIUI等)
- burpsuite小米手机抓包_Android 7.0+手机burpsuite抓包https
- android onresume方法,Android onActivityResult()和onResume()的执行顺序
- android 读取本地数据库db文件(Android sqlite)
- 安卓broadcastreceiver_Android手电筒原理
- android activitymanagerservice_安卓开发API
- android studio preview 不显示
- android 实现 搜索保存历史记录功能
- 【错误记录】Flutter / Android 报错 ( AAPT: error: attribute android:requestLegacyExternalStorage not found )
- 【Android 插件化】插件化框架整理
- 【Android Gradle 插件】Android Plugin DSL Reference 离线文档下载 ( GitHub 下载文档 | 查看文档 )
- 【ijkplayer】编译 Android 版本的 ijkplayer ② ( 切换到 k0.8.8 分支 | 执行 init-android.sh 脚本进行初始化操作 )
- Android File Transfer for mac(强大的安卓文件传输工具)
- 安卓(Android)云真机平台
- Android Studio 导入项目 出现安装Error:Cause: failed to find target with hash string ‘android-23’ 等错误详解手机开发
- Android上的Linux之旅:实现最佳体验(安卓linux系统)
- Android与Linux:一段持久而又充满变数的联系(安卓内核linux)
- Android N 将替代使用 OpenJDK
- 安卓编年史(27):Android 5.0 Lollipop——有史以来最重要的安卓版本
- 探索Linux世界之Android厨房:DIY个性化安卓系统(linux安卓厨房)
- Android实现PHP连接MySQL进行数据交互(android通过php连接mysql)
- 如何在 Android 中使用 MySQL 数据库?(mysql安卓)
- cocos2d-2.0-x-2.0.3交叉编译到android报错解决
- Android发送GET与POST请求的DEMO详解
- 解析Android中webview和js之间的交互