发布于 2017-06-13 10:18:59 | 193 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


这篇文章主要介绍了Android 获取屏幕尺寸实例代码的相关资料,需要的朋友可以参考下

Android 获取屏幕尺寸实例代码

实现代码:


/** 
 * <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)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务