[안드로이드] 실제 화면 크기 구하기
프로그래밍/안드로이드2016. 8. 24. 16:59
반응형
12345678910111213141516171819202122232425262728293031323334 Display display1 = getWindowManager().getDefaultDisplay();int realWidth;int realHeight;if (Build.VERSION.SDK_INT >= 17){//new pleasant way to get real metricsDisplayMetrics realMetrics = new DisplayMetrics();display1.getRealMetrics(realMetrics);realWidth = realMetrics.widthPixels;realHeight = realMetrics.heightPixels;Log.i("sinwho","SDK >=17 RealWdith = " + realWidth + " RealHeight = " + realHeight);} else if (Build.VERSION.SDK_INT >= 14) {//reflection for this weird in-between timetry {Method mGetRawH = Display.class.getMethod("getRawHeight");Method mGetRawW = Display.class.getMethod("getRawWidth");realWidth = (Integer) mGetRawW.invoke(display1);realHeight = (Integer) mGetRawH.invoke(display1);Log.i("sinwho","SDK >=14 RealWdith = " + realWidth + " RealHeight = " + realHeight);} catch (Exception e) {//this may not be 100% accurate, but it's all we've gotrealWidth = display1.getWidth();realHeight = display1.getHeight();Log.i("Display Info", "Couldn't use reflection to get the real display metrics.");}} else {//This should be close, as lower API devices should not have window navigation barsrealWidth = display1.getWidth();realHeight = display1.getHeight();Log.i("sinwho","RealWdith = " + realWidth + " RealHeight = " + realHeight);}}cs
반응형
'프로그래밍 > 안드로이드' 카테고리의 다른 글
[안드로이드] 카메라 프리뷰 확대(줌) (0) | 2016.08.25 |
---|---|
[안드로이드] 버전별 사용자수 확인 (0) | 2016.08.24 |
[추천앱] 채널 번호 모를때 '채널 번호/TV 편성표' 앱 (0) | 2016.07.19 |
[안드로이드] 버튼 클릭 처리 (0) | 2016.06.23 |
[안드로이드] Paint 속성 및 메서드 (0) | 2016.06.22 |