Android 获取屏幕尺寸实例代码
程序员文章站
2023-12-09 20:38:09
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
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!