android中获取手机分辨率

news/2025/3/25 21:51:23/

在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.


http://www.ppmy.cn/news/161899.html

相关文章

JUC-13. JMM

想了解更多JUC的知识——JUC并发编程合集 1. Java内存模型 JMM&#xff08;Java内存模型Java Memory Model,简称JMM&#xff09;本身是一种抽象的概念&#xff0c;并不真实存在&#xff0c;它描述的是一组规则或规范&#xff0c;通过规范定制了程序中各个变量(包括实例字段,静…

j2me

J2ME程序开发全方位基础讲解汇总一、J2ME中需要的Java基础知识现在有大部分人&#xff0c;都是从零开始学J2ME的&#xff0c;学习J2ME的时候&#xff0c;总是从Java基础开始学习&#xff0c;而且现在讲Java基础的书籍中都是以J2SE来讲基础&#xff0c;这就给学习造成了一些不必…

J2ME (Java 2 Micro Edition) 简介

■前言 如果您曾经到http://www.javasoft.com 网站上查询有关Java 2 Micro Edition 的资料&#xff0c;十之八九会被一大堆的技术名词搞的一头雾水。什么 KVM &#xff0c;什么CLDC 、CDC 、MIDP &#xff0c;後面还冒出了Personal Java 、Embedde d Java以及JES 等名词。…

里程碑2在Win7下刷机问题

新买了一个里程碑2&#xff0c;准备研究一下android开发&#xff0c;看到网上的ME722 Rom出来了&#xff0c;这个是官方中文的&#xff0c;所以就开始了刷机的过程 刷机教程网上很多&#xff0c;google一下就可以了。 我这里主要说一下MS2的不同和我遇到的问题&#xff0c;因…

J2ME概述(转)

我们将从定义 J2ME 开始&#xff0c;从最简单的J2ME 是什么开始讲起。然后讨论它的总体架构并学习 J2ME 目标设备。作为架构讨论的一部分&#xff0c;我们将提供有关简表和配置的概述。同时我们会简要介绍打包和配置 J2ME 应用程序过程中的一些注意事项。 J2ME 是什么&#xf…

pcm 转 G711a/u

pcm 转 g711a(输入13位编成8位) 1.将pcm二进制 转成 排列&#xff1a;x xx…x1 xxxx xxxx… 2.符号位取反 3.根据从高位起&#xff0c;第一个 1 的位数 查表 4.wxyz为 第一个 1 后四位 5.获取完 seeewxyz 之后&#xff0c;除符号位外&#xff0c;其他位 偶数位取反 奇数位保…

USB2.0 集线器 GM8220

1 产品概述 芯片为一款支持 USB2.0 的 4 端口集线器&#xff0c;充分满足 USB2.0 和充电协议&#xff08;BC1.1/1.2&#xff09;。 器件有完整的扫描链&#xff0c;内建自测试模式&#xff0c;可工作在高速、全速、低速三种模式。芯片可 支持充电&#xff0c;可为便携式设备…

手机ME722设置Gmail账户方法

配置&#xff1a;ME722&#xff0c;系统为android 2.3.4 1、在“账户”->“添加账户”->“电子邮件”&#xff0c;输入邮件地址和密码 2、接收服务器设置&#xff0c;选择IMAP 服务器&#xff1a;imap.gmail.com&#xff0c;在高级设置里选中“使用安全连接”&#xff0…