分析各种Android设备屏幕分辨率与适配

摘要:
1、 数据收集源代码GitHub地址:--SSH:git@github.com:han1202012/DisplayTest.git;--HTTP:https://github.com/han1202012/DisplayTest ;. 使用以下程序在不同的设备上运行:packageshuliang.han.displaytest;importandroid.app.活动;重要的
一. 数据采集

 

 

源码GitHub地址 : 

-- SSH : git@github.com:han1202012/DisplayTest.git;

-- HTTP : https://github.com/han1202012/DisplayTest;

 

.

使用下面的程序运行在不同设备上 :  

  1. package shuliang.han.displaytest;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.util.DisplayMetrics;  
  6.   
  7. public class MainActivity extends Activity {  
  8.   
  9.     //屏幕的宽高, 单位像素  
  10.     private int screenWidth;  
  11.     private int screenHeight;  
  12.       
  13.     //屏幕的密度  
  14.     private float density;  //只有五种情况 : 0.75/ 1.0/ 1.5/ 2.0/ 3.0  
  15.     private int densityDpi; //只有五种情况 : 120/ 160/ 240/ 320/ 480  
  16.       
  17.     //水平垂直精确密度  
  18.     private float xdpi; //水平方向上的准确密度, 即每英寸的像素点  
  19.     private float ydpi; //垂直方向上的准确密度, 即没音村的像素点  
  20.       
  21.     @Override  
  22.     protected void onCreate(Bundle savedInstanceState) {  
  23.         super.onCreate(savedInstanceState);  
  24.         setContentView(R.layout.activity_main);  
  25.           
  26. //      getPixelWindowManager();  
  27. //      getPixelDisplayMetrics();  
  28.         getPixelDisplayMetricsII();  
  29.           
  30.         System.out.println("宽:" + screenWidth + ", 高:"+screenHeight);  
  31.         System.out.println("密度 density:" + density + ",densityDpi:" +densityDpi);  
  32.         System.out.println("精确密度 xdpi:" + xdpi + ", ydpi:" + ydpi);  
  33.     }  
  34.       
  35.     private void getPixelWindowManager() {  
  36.         screenWidth = getWindowManager().getDefaultDisplay().getWidth();  
  37.         screenHeight = getWindowManager().getDefaultDisplay().getHeight();  
  38.     }  
  39.       
  40.     private void getPixelDisplayMetrics() {  
  41.         DisplayMetrics dm = new DisplayMetrics();  
  42.         dm = getResources().getDisplayMetrics();  
  43.           
  44.         screenWidth = dm.widthPixels;  
  45.         screenHeight = dm.heightPixels;  
  46.           
  47.         density = dm.density;  
  48.         densityDpi = dm.densityDpi;  
  49.           
  50.         xdpi = dm.xdpi;  
  51.         ydpi = dm.ydpi;  
  52.     }  
  53.       
  54.     private void getPixelDisplayMetricsII() {  
  55.         DisplayMetrics dm = new DisplayMetrics();  
  56.         getWindowManager().getDefaultDisplay().getMetrics(dm);  
  57.           
  58.         screenWidth = dm.widthPixels;  
  59.         screenHeight = dm.heightPixels;  
  60.           
  61.         density = dm.density;  
  62.         densityDpi = dm.densityDpi;  
  63.           
  64.         xdpi = dm.xdpi;  
  65.         ydpi = dm.ydpi;  
  66.     }  
  67. }  



 

1. 三星 GT-N8000 平板

 

设备规格 : 

-- 屏幕尺寸10.1英寸
-- 屏幕分辨率WXGA TFT 1280x800
-- 屏幕比例16:9 
-- 屏幕类型TFT

 

运行程序采集的数据 :  

  1. 02-22 16:21:11.230: I/System.out(29911): 宽:1280, 高:752  
  2. 02-22 16:21:11.230: I/System.out(29911): 密度 density:1.0,densityDpi:160  
  3. 02-22 16:21:11.230: I/System.out(29911): 精确密度 xdpi:149.82489, ydpi:150.51852  

 

布局文件 :  

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="1280dp"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="#FF0000"  
  11.         android:text="@string/hello_world" />  
  12.   
  13. </LinearLayout>  



 

 

运行效果 : 

分析各种Android设备屏幕分辨率与适配第1张



2. 三星 P-601平板

 

设备规格 

-- 屏幕尺寸 :10.1英寸
-- 屏幕分辨率 :2560x1600
-- 屏幕比例 :16:9
-- 屏幕类型 :TFT

 

运行程序后采集的数据 :  

  1. 02-28 10:30:55.338: I/System.out(18566): 宽:2560, 高:1600  
  2. 02-28 10:30:55.338: I/System.out(18566): 密度 density:2.0,densityDpi:320  
  3. 02-28 10:30:55.338: I/System.out(18566): 精确密度 xdpi:301.037, ydpi:301.037  


布局文件 : 

  

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="1280dp"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="#FF0000"  
  11.         android:text="@string/hello_world" />  
  12.   
  13. </LinearLayout>  


效果图 : 

分析各种Android设备屏幕分辨率与适配第2张

 

XML文件 :  

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="1270dp"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="#FF0000"  
  11.         android:text="@string/hello_world" />  
  12.   
  13. </LinearLayout>  

效果图 : 1280dp能布满屏幕, 1270dp差一点布满屏幕;

分析各种Android设备屏幕分辨率与适配第3张

 

 

 

 

3. 三星Galaaxy Note3 SM-N9002

 

设备规格 : 

-- 屏幕尺寸 : 5.7英寸
-- 屏幕色彩 : 1600万色
-- 屏幕材质 : Super AMOLED
-- 分辨率 : 1920*1080
-- 触摸屏 : 电容屏

 

运行程序采集的数据  

  1. 02-28 10:37:48.960: I/System.out(5770): 宽:1080, 高:1920  
  2. 02-28 10:37:48.960: I/System.out(5770): 密度 density:3.0,densityDpi:480  
  3. 02-28 10:37:48.960: I/System.out(5770): 精确密度 xdpi:386.366, ydpi:387.047  


XML布局文件 :  

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="360dp"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="#FF0000"  
  11.         android:text="@string/hello_world" />  
  12.   
  13. </LinearLayout>  


效果图 : 360dp 是正好能布满整个屏幕.

分析各种Android设备屏幕分辨率与适配第4张

 

XML布局文件 :  

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="350dp"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="#FF0000"  
  11.         android:text="@string/hello_world" />  
  12.   
  13. </LinearLayout>  


效果图 : 350dp 就差一点布满全屏;

分析各种Android设备屏幕分辨率与适配第5张

.

 

 

4. 三星 GT-I9220

 

规格参数 

-- 屏幕尺寸 : 6.3英寸
-- 屏幕色彩 : 1600万色
-- 屏幕材质 : Super Clear LCD
-- 分辨率 : 1280 x 720

 

运行程序收集的数据 :  

  1. 02-28 11:09:10.848: I/System.out(17853): 宽:800, 高:1280  
  2. 02-28 11:09:10.848: I/System.out(17853): 密度 density:2.0,densityDpi:320  
  3. 02-28 11:09:10.848: I/System.out(17853): 精确密度 xdpi:317.5, ydpi:306.71698  



XML布局文件 :  

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="400dp"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="#FF0000"  
  11.         android:text="@string/hello_world" />  
  12.   
  13. </LinearLayout>  


效果图 : 

分析各种Android设备屏幕分辨率与适配第6张

 

XML布局文件 :  

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="390dp"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="#FF0000"  
  11.         android:text="@string/hello_world" />  
  12.   
  13. </LinearLayout>  



效果图 : 

分析各种Android设备屏幕分辨率与适配第7张

 

 

5. 青橙 GO M2S

 

规格参数 

-- 屏幕分辨率 : 480 X 800

-- 屏幕材质 : TFT

-- 屏幕尺寸 : 124.2×63.8×10.45毫米

 

运行程序采集数据  

  1. 02-28 11:16:08.254: I/System.out(31888): 宽:480, 高:800  
  2. 02-28 11:16:08.254: I/System.out(31888): 密度 density:1.5,densityDpi:240  
  3. 02-28 11:16:08.254: I/System.out(31888): 精确密度 xdpi:160.42105, ydpi:160.0  


XML布局文件 : 320dp占满全屏; 

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="320dp"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="#FF0000"  
  11.         android:text="@string/hello_world" />  
  12.   
  13. </LinearLayout>  


效果图 : 

分析各种Android设备屏幕分辨率与适配第8张

 

XML布局文件 :  

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="310dp"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="#FF0000"  
  11.         android:text="@string/hello_world" />  
  12.   
  13. </LinearLayout>  


效果图 : 310dp差一点占满全屏;

分析各种Android设备屏幕分辨率与适配第9张

 

6. 联想 s890

 

规格参数 : 5英寸 960x540像素

 

 

运行程序收集数据 :  

  1. 02-28 11:27:27.330: I/System.out(7708): 宽:540, 高:960  
  2. 02-28 11:27:27.330: I/System.out(7708): 密度 density:1.5,densityDpi:240  
  3. 02-28 11:27:27.330: I/System.out(7708): 精确密度 xdpi:240.0, ydpi:240.0  



XML布局文件 :  

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="360dp"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="#FF0000"  
  11.         android:text="@string/hello_world" />  
  12.   
  13. </LinearLayout>  


效果图 : 360dp 布满全屏;

分析各种Android设备屏幕分辨率与适配第10张

 

XML布局文件 :  

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="350dp"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="#FF0000"  
  11.         android:text="@string/hello_world" />  
  12.   
  13. </LinearLayout>  


效果图 : 350dp 差一点布满全屏

分析各种Android设备屏幕分辨率与适配第11张

 

7. 华为 D2-0082

 

规格参数 : 

-- 屏幕尺寸 : 5.0英寸;
-- 屏幕色彩 : 1600万色;
-- 屏幕材质 : IPS;
-- 分辨率 : 1920*1080;

 

 

运行程序采集的数据 :  

  1. 03-04 17:18:07.512: I/System.out(9435): 宽:1080, 高:1776  
  2. 03-04 17:18:07.516: I/System.out(9435): 密度 density:3.0,densityDpi:480  
  3. 03-04 17:18:07.516: I/System.out(9435): 精确密度 xdpi:442.4516, ydpi:443.34546  



XML布局文件 : 360dp 布满全屏; 

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="360dp"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="#FF0000"  
  11.         android:text="@string/hello_world" />  
  12.   
  13. </LinearLayout>  



效果图 : 

分析各种Android设备屏幕分辨率与适配第12张

 

XML布局文件 : 350dp 横向 差一点布满全屏; 

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="350dp"  
  9.         android:layout_height="wrap_content"  
  10.         android:background="#FF0000"  
  11.         android:text="@string/hello_world" />  
  12.   
  13. </LinearLayout>  


效果图 : 

分析各种Android设备屏幕分辨率与适配第13张

 

 

 

二. 数据分析

. 型号 分辨率 密度 归一化密度 水平物理密度 垂直物理密度

 

.

手机型号分辨率密度 | 宽度(dp) | 宽度(inch)归一化密度水平精确密度垂直物理密度
三星GT-N80001280 x 8001.0 | 1280dp | 8.54in160149.82489150.51852
三星P-6012560 x 16002.0 | 1280dp | 8.49in320301.037301.037 
三星SM-N90021080 x 19203.0 | 360dp | 2.795in480386.366387.047
三星GT-I9220720 x 12802.0 | 360dp | 2.68in320317.5306.71698
青橙GO M2S480 x 8001.5 | 320dp | 2.99in240160.42105160.0 
联想S980540 x 9601.5 | 360dp | 2.25in240240.0240.0
华为D2-00821080 x 19203.0 | 360dp | 2.44in480442.4516443.34546

. 有点凌乱啊, 先留着以后在总结;

 

现有公式 : 

-- 像素 和 设备独立像素 转换公式 : px = dp * densityDpi / 160 , density 是归一化密度;

-- 英寸数 和 分辨率 转换公式 : in = px / real_densityDpi , dpi 是真实的物理密度;

-- 设备独立像素 和 分辨率之间转换 : dp = px / density ;

 

物理长度计算 :

-- 根据设备独立像素计算实际物理长度 : in = px / real_densityDpi ; 

 

.

物理密度和归一化密度 :  有点凌乱, 哪个安卓大神能解释下为什么啊, 定义的标准时什么啊, 想怎么定义就怎么定义? 青橙手机是奇葩啊 !!! 先写到这 ╮(╯▽╰)╭

免责声明:文章转载自《分析各种Android设备屏幕分辨率与适配》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇windows ------ 证书的导出dubbo 配置文件详解下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Android 异步框架 RxJava2

观察者模式的概念 RxJava是android的异步框架,官方介绍是可观测的序列,组成异步基于事件程序的库。特点是观察者模式,基于事件流的链式调用,随着异步操作调度过程复杂的情况下,程序逻辑也变得越来越复杂,但RxJava依然能够保持简洁。 简单的说观察者A与被观察者B建立订阅关系,当被观察者B发生某种改变时,立即通知观察者A 添加依赖 compile '...

(转)PhoneGap开发环境搭建

(原)http://www.cnblogs.com/Random/archive/2011/12/28/2305398.html PhoneGap开发环境搭建   项目中要用PhoneGap开发,了解了下基本规则,记录一下,以备后查。(只针对Android平台) 一、安装 在安装PhoneGap开发环境之前,需要先安装以下框架: 1.Java SDK...

java第七天

p38~p41: 1、可以通过import 一个自定义类库(或者网上下的)在java中使用c风格的输入输出方式。 2、忘记优先顺序时应该用括号明确规定计算顺序。 3、java的操作符不同于c++,几乎只能操作“基本类型”,例外的是 ==、!=、=能操作所有对象,除此之外,String类支持“+”和“+=”。 4、System.out.print()语句中包...

Scala入门系列(十一):模式匹配

引言 模式匹配是Scala中非常有特色,非常强大的一种功能。 类似于Java中的switch case语法,但是模式匹配的功能要比它强大得多,switch只能对值进行匹配,但是Scala的模式匹配除了可以对值进行匹配之外,还可以对类型进行匹配、对Array和List的元素情况进行匹配、对case class进行匹配甚至对有值或没值(Option)进行匹配...

golang json解析

前言 Go 语言自带的 encode/json 包提供了对 JSON 数据格式的编码和解码能力。 解析 JSON 的关键,其实在于如何声明存放解析后数据的变量的类型。 此外使用 json 编码还会有几个需要注意的地方,谨防踩坑。 解析简单JSON 先观察下这段 JSON 数据的组成,name,created 是字符串。id 是整型,fruit 是一个字符串...

使用电脑模拟微信内置浏览器

最近在弄微信开发,需要微信请求,其实很好改 只要把请求头改了就好了。 浏览器呢 就使用 chrome我在这使用360极速浏览器了。 首先进入开发者模式(F12或者右键审查元素) 如图: 然后 点击 更多 选 More tools 打开Network conditions 最后设置请求为微信请求: 最后那个请求是自...