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


相关推荐

  • python modis数据拼接_python读取modis数据

    python modis数据拼接_python读取modis数据本期记录只上干活,废话不多说,主要是后面与HEG配合使用,实现一系列研究与反演操作。python环境:Python3.5.2+Pycharm模块包:pyhdf安装方法(命令行输入):pipinstallpyhdf一、获取hdf数据集:frompyhdf.SDimportSDHDF_FILR_URL=”E:\Persona_project\Py-Program\RS\modis\M…

    2025年6月24日
    1
  • dell服务器如何恢复掉线硬盘阵列

    dell服务器如何恢复掉线硬盘阵列如果一个RAID5中有两块硬盘掉线,理论上来说,这个RAID阵列彻底失效,数据全部丢失,无法恢复。此时,如果数据非常重要,建议寻求专业的数据恢复公司帮助。如果想要自己尝试,此时有很小的几率可以修复。进入RAID卡配置界面后,选择objects-logical drive–对象,逻辑驱动器看到两块硬盘的状态都是failed–失败,如下:如果知道哪块硬盘是后掉线的,就将这个

    2022年6月26日
    266
  • spring注解@Conditional 按照一定的条件进行判断,满足条件给容器中注册bean

    spring注解@Conditional 按照一定的条件进行判断,满足条件给容器中注册beanpublicclassPerson{ privateStringname; privateintage; publicStringgetName(){ returnname; } publicvoidsetName(Stringname){ this.name=name; } publicintgetAge(){…

    2025年7月30日
    0
  • 工业大数据漫谈5:工业大数据案例(上)

    工业大数据漫谈5:工业大数据案例(上)今天,整理了一些工业大数据的相关案例,看看各家企业是如何成功实施工业大数据的。    1、能够实现全生产过程的信息透明化的案例    通过采用集成自动化与驱动解决方案,能够显著提高生产效率和灵活性。原东德玻璃制造商f|glass就是一个很好的实例。它的工厂可以算得上是全世界最先进、最节能的工厂之一了。该工厂采用了一套集成自动化解决方案、一个先进的能源管理系统以及一个创新

    2022年6月5日
    29
  • MySQL时区问题_docker设置时区

    MySQL时区问题_docker设置时区使用mysql-connector-java-8.0.9-rc出现以下异常:解决方案:在url后面添加&amp;serverTimezone=GMT%2B8,如:url:jdbc:mysql://localhost:3306/activiti?useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false&amp;serve…

    2025年6月29日
    0
  • pycharm多行代码同时注释、去除注释_解除注释的快捷键

    pycharm多行代码同时注释、去除注释_解除注释的快捷键1.单行多行注释快捷键:ctrl+/2.取消单行多行注释快捷键:ctrl+/

    2022年8月29日
    0

发表回复

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

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