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

android 获取屏幕分辨率_安卓系统分辨率设置在Activity中  //ME722测试480*854  竖屏Displaydisplay=this.getWindowManager().getDefaultDisplay();intnHeight=display.getHeight();     //569intnWidth=display.getWidth();       //320Displa

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

在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.net/170370.html原文链接:https://javaforall.net

(0)
上一篇 2022年8月13日 上午6:16
下一篇 2022年8月13日 上午6:16


相关推荐

  • vue如何生成二维码_vue实现扫描二维码

    vue如何生成二维码_vue实现扫描二维码这里介绍两种vue生成二维码的方法QRcodevue-qrvue-qr比QRcode功能多在可以在中间加logo下面先介绍QRcodevue里安装qrcodejs的npm包npminstallqrcodejs2importQRCodefrom‘qrcodejs2’methods:{creatQrCode(){varqrcode=newQRCode(t…

    2022年10月3日
    4
  • pig中使用的一些实例语法

    pig中使用的一些实例语法

    2021年12月15日
    55
  • 解决idea中maven项目的pom文件不会自动下载jar包问题 + 更新不完整依赖命令

    解决idea中maven项目的pom文件不会自动下载jar包问题 + 更新不完整依赖命令不会自动下载jar包idea昨天还在正常使用,结果今天发现pom文件中的依赖不会自动下载了,最后百度找到了解决方案: setting——>maven——>去掉workoffline的勾,问题解决!但是我之前用着还是没有这个问题的,百度发现可能是Intellijideasetting显示出错/或者电脑运行过久出错,在经历几次重启I…

    2022年5月11日
    79
  • apk逆向激活成功教程入门级[通俗易懂]

    apk逆向激活成功教程入门级[通俗易懂]样本很简单,就只有个发短信的行为,内容加密,可以直接写解密方法解密,但是这里我想通过hook解密方法直接动态看解密内容。动态跑发现并没有运行到解密方法那里,查看代码发现解密前有个if没通过:试着反编译修改代码找到对应的smali代码删除掉重新编译生成apk搞定。新生成的apk成功删除掉了if判断那块代码最后hook解密方法动态看到解密内容附上样本:链接:https://p…

    2025年12月1日
    8
  • c语言switch例题注释,switch语句例子大全 C语言switch语句例题

    c语言switch例题注释,switch语句例子大全 C语言switch语句例题CSS布局HTML小编今天和大家分享一个switch语句的例子matlab中switch语句的用法例子matlab中switch语句看了好几本教材上的例子都未看懂核心,不知谁能提供if-else-end语句所对应的是多重判断选择,而有时也会遇到多分支判断选择的问题。MATLAB语言为解决多分支判断选择提供了switch-case语句。switch-case语句的一般表达形式为:switch〈…

    2022年10月21日
    3
  • 漫画大全更新了吗_所有的漫画台

    漫画大全更新了吗_所有的漫画台无会员,10万+本漫画,统统免费!!!最新最热门的免费漫画大全,最全最二次元的撸漫平台,超多正版高清彩漫尽在漫画大全APP!《斗罗大陆》《斗破苍穹》《凤逆天下》《妃夕妍雪》《穿越西元3000后》《纯情丫头火辣辣》《勇者是女孩》《龙族》《哑舍》《暴走邻家》等等,全部免费,喜欢的统统都到碗里来!!!欢迎下载使用 …

    2022年10月8日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号