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 

相关文章:

  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2022-01-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
  • 2021-09-04
  • 2021-06-16
  • 2022-12-23
  • 2022-02-22
相关资源
相似解决方案