码迷,mamicode.com
首页 > 移动开发 > 详细

Android获取设备屏幕宽高像素值的两个方法

时间:2018-04-26 01:12:52      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:结果   and   输出   roi   star   zhang   efault   1.5   sources   

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 

Android获取设备屏幕宽高像素值的两个方法

标签:结果   and   输出   roi   star   zhang   efault   1.5   sources   

原文地址:https://www.cnblogs.com/rianbowymail/p/8947580.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!