android 获取屏幕尺寸

<pre style="font-family: 宋体; font-size: 9pt; background-color: rgb(255, 255, 255);"><pre name="code" class="java">/**
 * <supports-screens
 * android:smallScreens="true"
 * android:normalScreens="true"
 * android:largeScreens="true"
 * android:resizeable="true"
 * android:anyDensity="true" />
 * <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8" />
 * 使Android程序支持了多种分辨率
 */
int mWidthScreen,mHeightScreen;

Display display = getWindowManager().getDefaultDisplay();
mWidthScreen = display.getWidth();
mHeightScreen = display.getHeight();
LogUtils.e("Width:" + display.getWidth());
LogUtils.e("Height:" + display.getHeight());

WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
mWidthScreen = outMetrics.widthPixels;
mHeightScreen = outMetrics.heightPixels;
LogUtils.e("Width:" + outMetrics.widthPixels);
LogUtils.e("Height:" + outMetrics.heightPixels);
LogUtils.e("xdpi:" + outMetrics.xdpi);
LogUtils.e("ydpi:" + outMetrics.ydpi);
LogUtils.e("densityDpi:" + outMetrics.densityDpi);
LogUtils.e("density:" + outMetrics.density);
LogUtils.e("scaledDensity:" + outMetrics.scaledDensity);
LogUtils.e("spWidth:"  + (outMetrics.widthPixels / outMetrics.scaledDensity + 0.5f));
LogUtils.e("spHeight:"  + (outMetrics.heightPixels / outMetrics.scaledDensity + 0.5f));
LogUtils.e("dpWidth:" + (outMetrics.widthPixels / outMetrics.density + 0.5f));
LogUtils.e("dpHeight:" + (outMetrics.heightPixels / outMetrics.density + 0.5f));

DisplayMetrics resMetrics = getResources().getDisplayMetrics();
mHeightScreen = resMetrics.heightPixels;
mWidthScreen = resMetrics.widthPixels;
LogUtils.e("Width:" + resMetrics.widthPixels);
LogUtils.e("Height:" + resMetrics.heightPixels);
LogUtils.e("xdpi:" + resMetrics.xdpi);
LogUtils.e("ydpi:" + resMetrics.ydpi);
LogUtils.e("densityDpi:" + resMetrics.densityDpi);
LogUtils.e("density:" + resMetrics.density);
LogUtils.e("scaledDensity:" + resMetrics.scaledDensity);
LogUtils.e("spWidth:"  + (int)(resMetrics.widthPixels / resMetrics.scaledDensity + 0.5f));
LogUtils.e("spHeight:"  + (int)(resMetrics.heightPixels / resMetrics.scaledDensity + 0.5f));
LogUtils.e("dpWidth:" + (resMetrics.widthPixels / resMetrics.density + 0.5f));
LogUtils.e("dpHeight:" + (resMetrics.heightPixels / resMetrics.density + 0.5f));


 
 


屏幕适配比

px                   dpi          scale      dip
480x850        240        1.5          320x569
540x960        240        1.5          360x640
640x960        320         2.0         320x480
600x1024      240        1.5          400x683
720x1280      240        1.5          480x853
720x1280      320        2.0          360x640
768x1280      320        2.0          384x640
800x1280      213       1.331       601x962
800x1280      320        2.0          400x640
1080x1920    420       2.625      411x731
1080x1920    480       3.0           360x640
1440x2560    560       3.5           411x731


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值