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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Apple Watch更懂女人心

    Apple Watch更懂女人心

    2021年8月31日
    72
  • linux 如何编译安装软件

    linux 如何编译安装软件

    2021年10月18日
    40
  • 格拉姆矩阵(Gram matrix)详细解读

    格拉姆矩阵(Gram matrix)详细解读目录基础知识-向量的内积Grammatrix介绍Grammatrix的应用-风格迁移一、基础知识-向量的内积1.1向量的内积定义:也叫向量的点乘,对两个向量执行内积运算,就是对这两个向

    2022年8月2日
    5
  • 【FPGA——工具篇】:Modelsim SE-64 10.4下载、破解、安装过程

    【FPGA——工具篇】:Modelsim SE-64 10.4下载、破解、安装过程ModelsimSE-6410.4破解安装过程百度云链接:https://pan.baidu.com/s/1ONbjNLajFKzHDJ9bs4gz6Q密码:by0p压缩包解压密码:Lily_9 ①执行软件的正常安装程序.exe,点点我同意神马的….(需要重启一次)②在软件安装目录中找到mgls64.dll文件,右键文件属性取消只读属性。mgls64.dll文件的默认路径…

    2022年5月23日
    38
  • 使用PyTorch搭建ResNet34网络

    使用PyTorch搭建ResNet34网络ResNet34 网络结构先上图参照 ResNet18 的搭建 由于 34 层和 18 层几乎相同 叠加卷积单元数即可 所以没有写注释 具体可以参考我的 ResNet18 搭建中的注释 ResNet34 的训练部分也可以参照 importtorchi nnasnnfromto nnimportfunc nn Module def init self in channel out chann

    2025年6月8日
    0
  • 字典树详解「建议收藏」

    字典树详解「建议收藏」字典树字典树(又叫单词查找树、TrieTree),是一种树形结构,典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串)。主要思想是利用字符串的公共前缀来节约存储空间。很好地利用了串的公共前缀,节约了存储空间。字典树主要包含两种操作,插入和查找 是一种哈希树的变种,常用于,统计,排序,保存大量字符串(但不仅限于字符串),主要实现方法是利用串的公共前缀来减少查询时间,减少了不必要的比较,不仅…

    2022年9月7日
    0

发表回复

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

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