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.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/170370.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 影视3D建模和游戏3D建模对比,哪个更有发展前景

    影视3D建模和游戏3D建模对比,哪个更有发展前景影视3D建模和游戏3D建模,两者之间最大和最明显的差异是:游戏开发永远有多边形建模预算。影视建模方面,对于多边形数量都没有限制。对于电影来说,唯一限制是时间,按时,按预算生产合格的模型。游戏建模设计不能随意增加多边形面数,必须依靠纹理细节提升模型的质量。由于多边形数量必须很低,需要其他方法将更多细节放入模型中,目前最好的方法当然是使用纹理。游戏建模设计技术游戏中经常使用的技术是细节层次。意味单个游戏会有几个不同的细节级别。玩家离模型越远,资产的细节就越少。随着玩家越来越近,较低分辨率模型将被.

  • 软件激活成功教程入门_软件激活成功教程修改内容

    软件激活成功教程入门_软件激活成功教程修改内容大家好我是长生第一次开通博客主要是为了记录我在激活成功教程学习中遇到的问题以及解决办法 激活成功教程初级入门第一步有壳查壳无壳直接载入OD 第二步 先打开OD 右键搜索ASCII 第三部crtl+f 搜索 注册失败关键提示字符第四步       返回OD主界面 在提示注册失败字符上方 寻找关键je 与关键jne,一般大跳即为关键跳,这个时候右键nop填充,在保存文件 这个时候…

  • Center OS 7 下的安装Apache「建议收藏」

    Center OS 7 下的安装Apache「建议收藏」使用yum安装,直接yuminstallhttpd

  • java自学经验(基础)

    屌丝逆袭,成神之路

  • 全局平均池化(global-average-pooling)

    全局平均池化在很多视觉任务中会用到。之前对darknet-53结构分析的时候,特别留意了一下全局平局池化。其实,这个操作就是它的字面意思:把特征图全局平均一下输出一个值,也就是把W*H*D的一个张量变成1*1*D的张量。下列引用来自stackoverflow:WithGlobalpoolingreducesthedimensionalityfrom3Dto1D.The…

  • preference用法for_interference用法

    preference用法for_interference用法文章目录PreferenceFragment简介PreferenceFragment使用PreferenceFragment扩展PreferenceFragment简介在我们写一个项目的时候,基本都有选项设置界面,这类设置界面的原理基本都是本地的一些个性化设置,通过读取本地设置来改变某些差异显示(例如字体大小,主题颜色,WIFI自动下载等)。这些设置一般都会使用Preference来保存,…

发表回复

您的电子邮箱地址不会被公开。

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