首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >android 获取屏幕分辨率_安卓系统分辨率设置

android 获取屏幕分辨率_安卓系统分辨率设置

作者头像
全栈程序员站长
发布2022-09-21 16:12:04
发布2022-09-21 16:12:04
2.5K0
举报

大家好,又见面了,我是你们的朋友全栈君

在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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Constants
    • public static final int DENSITY_DEFAULT
    • public static final int DENSITY_HIGH
    • public static final int DENSITY_LOW
    • public static final int DENSITY_MEDIUM
    • public static final int DENSITY_XHIGH
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档