分析各種Android設備屏幕分辨率與適配 - 使用大量真實安卓設備采集真實數據統計


一. 數據采集

 

 

源碼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>  



 

 

 

運行效果 : 




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>  


效果圖 : 

 


 

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差一點布滿屏幕;

 

 

 

 

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 是正好能布滿整個屏幕.

 


 

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 就差一點布滿全屏;

 


.

 

 

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>  


效果圖 : 

 


 

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>  



 

效果圖 : 


 

 

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>  


效果圖 : 

 


 

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差一點占滿全屏;

 


 

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 布滿全屏;

 


 

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 差一點布滿全屏

 


 

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>  



 

效果圖 : 


 

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>  


效果圖 : 

 


 

 

 

二. 數據分析

 

 

. 型號 分辨率 密度 歸一化密度 水平物理密度 垂直物理密度

 

.

 

手機型號 分辨率 密度 | 寬度(dp) | 寬度(inch) 歸一化密度 水平精確密度 垂直物理密度
三星GT-N8000 1280 x 800 1.0 | 1280dp | 8.54in 160 149.82489 150.51852
三星P-601 2560 x 1600 2.0 | 1280dp | 8.49in 320 301.037 301.037 
三星SM-N9002 1080 x 1920 3.0 | 360dp | 2.795in 480 386.366 387.047
三星GT-I9220 720 x 1280 2.0 | 360dp | 2.68in 320 317.5 306.71698
青橙GO M2S 480 x 800 1.5 | 320dp | 2.99in 240 160.42105 160.0 
聯想S980 540 x 960 1.5 | 360dp | 2.25in 240 240.0 240.0
華為D2-0082 1080 x 1920 3.0 | 360dp | 2.44in 480 442.4516 443.34546

 

 

. 有點凌亂啊, 先留着以后在總結;

 

現有公式 : 

-- 像素 和 設備獨立像素 轉換公式 : px = dp * densityDpi / 160 , density 是歸一化密度;

-- 英寸數 和 分辨率 轉換公式 : in = px / real_densityDpi , dpi 是真實的物理密度;

-- 設備獨立像素 和 分辨率之間轉換 : dp = px / density ;

 

物理長度計算 :

-- 根據設備獨立像素計算實際物理長度 : in = px / real_densityDpi ; 

 

.

物理密度和歸一化密度 :  有點凌亂, 哪個安卓大神能解釋下為什么啊, 定義的標准時什么啊, 想怎么定義就怎么定義? 青橙手機是奇葩啊 !!! 先寫到這 ╮(╯▽╰)╭


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM