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

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

        TextView text = (TextView)findViewById(R.id.text);
        DisplayMetrics dm = new DisplayMetrics();
        text.append("getResources().getDisplayMetrics()");
        text.append("\n=========================\n");          
        dm = getResources().getDisplayMetrics();
        text.append("density: "+dm.density);
        text.append("\n");
        
        text.append("densityDpi: "+dm.densityDpi);
        text.append("\n");
        
        text.append("scaledDensity: "+dm.scaledDensity);
        text.append("\n");
        
        text.append("[width,height]: ["+dm.widthPixels+","+dm.heightPixels+"]");
        text.append("\n");   
        
        text.append("xdpi: "+dm.xdpi);
        text.append("\n"); 
        
        text.append("ydpi: "+dm.ydpi);
        text.append("\n");  

        text.append("\n\n");   
        text.append("getResources().getConfiguration()");
        text.append("\n=========================\n");          
        Configuration conf = getResources().getConfiguration();
        text.append("fontScale: "+conf.fontScale);
        text.append("\n");
        
        text.append("hardKeyboardHidden: "+conf.hardKeyboardHidden);
        text.append("\n");
        
        text.append("keyboard: "+conf.keyboard);
        text.append("\n");
        
        text.append("mcc: "+conf.mcc);
        text.append("\n");
        
        text.append("mnc: "+conf.mnc);
        text.append("\n");
        
        text.append("navigation: "+conf.navigation);
        text.append("\n");
        
        text.append("navigationHidden: "+conf.navigationHidden);
        text.append("\n");
        
        text.append("orientation: "+conf.orientation);
        text.append("\n");
        
        text.append("screenHeightDp: "+conf.screenHeightDp);
        text.append("\n");
        
        text.append("screenLayout: "+conf.screenLayout);
        text.append("\n");
        
        text.append("screenWidthDp: "+conf.screenWidthDp);
        text.append("\n");
        
        text.append("smallestScreenWidthDp: "+conf.smallestScreenWidthDp);
        text.append("\n");
        
        text.append("touchscreen: "+conf.touchscreen);
        text.append("\n");
        
        text.append("uiMode: "+conf.uiMode);
        text.append("\n");
        
        text.append("describeContents: "+conf.describeContents());
        text.append("\n");

 

 

根据以上参数调整屏幕适配

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值