获取Android设备屏幕的相关参数

包含屏幕的分辨率  以及 屏幕宽度的最大dp 高度最大dp  

Java代码   收藏代码
  1. TextView text = (TextView)findViewById(R.id.text);  
  2. DisplayMetrics dm = new DisplayMetrics();  
  3. text.append("getResources().getDisplayMetrics()");  
  4. text.append("\n=========================\n");            
  5. dm = getResources().getDisplayMetrics();  
  6. text.append("density: "+dm.density);  
  7. text.append("\n");  
  8.   
  9. text.append("densityDpi: "+dm.densityDpi);  
  10. text.append("\n");  
  11.   
  12. text.append("scaledDensity: "+dm.scaledDensity);  
  13. text.append("\n");  
  14.   
  15. text.append("[width,height]: ["+dm.widthPixels+","+dm.heightPixels+"]");  
  16. text.append("\n");     
  17.   
  18. text.append("xdpi: "+dm.xdpi);  
  19. text.append("\n");   
  20.   
  21. text.append("ydpi: "+dm.ydpi);  
  22. text.append("\n");    
  23.   
  24. text.append("\n\n");     
  25. text.append("getResources().getConfiguration()");  
  26. text.append("\n=========================\n");            
  27. Configuration conf = getResources().getConfiguration();  
  28. text.append("fontScale: "+conf.fontScale);  
  29. text.append("\n");  
  30.   
  31. text.append("hardKeyboardHidden: "+conf.hardKeyboardHidden);  
  32. text.append("\n");  
  33.   
  34. text.append("keyboard: "+conf.keyboard);  
  35. text.append("\n");  
  36.   
  37. text.append("mcc: "+conf.mcc);  
  38. text.append("\n");  
  39.   
  40. text.append("mnc: "+conf.mnc);  
  41. text.append("\n");  
  42.   
  43. text.append("navigation: "+conf.navigation);  
  44. text.append("\n");  
  45.   
  46. text.append("navigationHidden: "+conf.navigationHidden);  
  47. text.append("\n");  
  48.   
  49. text.append("orientation: "+conf.orientation);  
  50. text.append("\n");  
  51.   
  52. text.append("screenHeightDp: "+conf.screenHeightDp);  
  53. text.append("\n");  
  54.   
  55. text.append("screenLayout: "+conf.screenLayout);  
  56. text.append("\n");  
  57.   
  58. text.append("screenWidthDp: "+conf.screenWidthDp);  
  59. text.append("\n");  
  60.   
  61. text.append("smallestScreenWidthDp: "+conf.smallestScreenWidthDp);  
  62. text.append("\n");  
  63.   
  64. text.append("touchscreen: "+conf.touchscreen);  
  65. text.append("\n");  
  66.   
  67. text.append("uiMode: "+conf.uiMode);  
  68. text.append("\n");  
  69.   
  70. text.append("describeContents: "+conf.describeContents());  
  71. text.append("\n");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值