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


相关推荐

  • 物联网是随着智能化技术的发展_嵌入式物联网开发

    物联网是随着智能化技术的发展_嵌入式物联网开发&#13;&#13;&#13;&#13;&#13;&#13;&#13;从谷歌的AlphaGo将人工智能推进大众视野起,在可预见的未来,人工智能会涉及到我们生活的各个方面,…

    2022年10月4日
    3
  • idea2021.2.2激活码永久-激活码分享[通俗易懂]

    (idea2021.2.2激活码永久)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html1STL5S9V8F-eyJsaWNlbnNlSW…

    2022年3月27日
    3.0K
  • 数据库优化-基准測试(一)

    数据库优化-基准測试(一)

    2022年2月3日
    41
  • matplotlib之pyplot模块——饼图(pie():圆环图(donut)、二层圆环图、三层圆环图(旭日图))「建议收藏」

    matplotlib之pyplot模块——饼图(pie():圆环图(donut)、二层圆环图、三层圆环图(旭日图))「建议收藏」在matplotlib中pie()不单可以绘制饼图,还可以绘制圆环图(donut)。圆环图可以看成饼图的变种,matplotlib没有提供专门绘制圆环图的接口。在matplotlib之pyplot模块之饼图(pie():基础参数,返回值)中,我们提到了wedgeprops参数,通过wedgeprops参数传递饼块对象Wedge的width参数即可快速实现圆环图。下面通过三个案例简单说明圆环图、二层圆环图、三层圆环图的制作方法。

    2022年9月25日
    2
  • vscode运行php配置_捷达vs5顶配啥配置

    vscode运行php配置_捷达vs5顶配啥配置这篇博文是当初笔者上课需要配置XAMPP,整理出来配置方法,错漏之处没有认真核对,给造成麻烦的同学道个歉。以下有两场修正之处。第一处,XAMPP国内下载地址改成了XAMPP中文网最新版本下载链接,给之前误下p2p的同学再次道个歉。第二处,下载xdebug插件-添加配置处配置信息已经修正,感谢评论区@SabreWulf2020同学另,水平有限暂时无法回复大家的私信问题,请谅解。一、下载XAMPPXAMPP是一个易于安装的Apache发行版,其中包含MariaDB、PHP和Perl。仅仅需要下载并.

    2022年9月22日
    1
  • fedora最新版本_软件源更新不出来

    fedora最新版本_软件源更新不出来首先,把当前的源配置文件备份。#mkdir~/repo.bak#mv/etc/yum.repos.d/*~/repo.bak添加文件/etc/yum.repos.d/sjtu.repo内容如下:(用vi、emacs、gedit就随便你了)#———————————————————–

    2022年9月20日
    3

发表回复

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

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