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


相关推荐

  • 游戏 海外推广_手游礼包助手

    游戏 海外推广_手游礼包助手最近,网上正在热烈地讨论起优质游戏版号买卖的“生意经”了。国内手游的这条路,走得越来越不容易,现在正卡在了游戏版号这个瓶颈上,呼吸困难。而且国内的手游市场已经被大型企业比如腾讯和网易等巨头所占据,中小型的游戏厂商的出路在哪里?不用问,他们走上了出海之路!出海之路离不开手游APP的推广和营销,为了把钱花到刀刃上,需要了解怎么提升海外手游APP推广的ROI?我们选择了关于推广海外手游并提升ROI的四…

    2025年7月17日
    6
  • phpstorm 激活码2021(破解版激活)

    phpstorm 激活码2021(破解版激活),https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月16日
    218
  • 最近做RTSP流媒体的实时广播节目

    最近做RTSP流媒体的实时广播节目

    2022年1月14日
    50
  • 文本分类算法综述

    文本分类算法综述文本分类大致有两种方法:一种是基于训练集的文本分类方法;另一种是基于分类词表的文本分类方法。两种方法出自不同角度的研究者,训练集法更多的来自计算机或人工智能研究领域,而分类表法则更多地来自突出情报领域。本文主要介绍前一种。基于训练集的文本分类是一种典型的有教师的机器学习问题,一般分为训练和分类两个阶段,具体过程如下:训练阶段:1)             定义类别集合 ,这些类别可是是层次式的,…

    2022年6月9日
    35
  • 常见浏览器兼容性问题与解决方案

    常见浏览器兼容性问题与解决方案所谓的浏览器兼容性问题 是指因为不同的浏览器对同一段代码有不同的解析 造成页面显示效果不统一的情况 在大多数情况下 我们的需求是 无论用户用什么浏览器来查看我们的网站或者登陆我们的系统 都应该是统一的显示效果 所以浏览器的兼容性问题是前端开发人员经常会碰到和必须要解决的问题 在学习浏览器兼容性之前 我想把前端开发人员划分为两类 第一类是精确按照设计图开发的前端开发人员 可以说是精确到 1

    2025年8月24日
    4
  • vscode快捷键重置及快捷键恢复

    vscode快捷键重置及快捷键恢复在用vscode设置快捷键的时候,有的快捷键和自己设置的有重复和冲突现象,为了图方便我把与自己冲突的快捷键都删除了,结果导致键盘的删除按键用不了,相当于自己写的代码无法删除了。最后还是在官网上找到解决办法。 首先找到键盘快捷设置 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20191128152918849.png) ![在这里插入图片描述](http…

    2022年6月9日
    621

发表回复

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

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