Android獲取設備屏幕寬高像素值的兩個方法


private void get1() {  
    Resources resources = this.getResources();  
    DisplayMetrics dm = resources.getDisplayMetrics();  
    int width = dm.widthPixels;  
    int height = dm.heightPixels;  
    Log.d("方法1", width + " , " + height);  
}  
  
private void get2() {  
    WindowManager manager = this.getWindowManager();  
    DisplayMetrics outMetrics = new DisplayMetrics();  
    manager.getDefaultDisplay().getMetrics(outMetrics);  
    int width = outMetrics.widthPixels;  
    int height = outMetrics.heightPixels;  
    Log.d("方法2", width + " , " + height);  
}  

  輸出結果一致:

  1. 04-20 10:11:41.513 27052-27052/zhangphil.test D/方法1: 1080 , 2040  
  2. 04-20 10:11:41.514 27052-27052/zhangphil.test D/方法2: 1080 , 2040 


免責聲明!

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



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