Please Enable JavaScript!
Gon[ Enable JavaScript ]

안드로이드(Android) getWidth() from the type Display is deprecated 수정

안드로이드 개발
반응형

안드로이드(Android) getWidth() from the type Display is deprecated 수정

 

환경 : Eclipse Mars, Android 4.2.2

 

스마트폰 화면의 가로와 세로 픽셀값을 알아오는 함수인 getWidth(), getHeight() deprecated 되었습니다.

 

 

이것을 수정하기 위해 안드로이드 개발사이트에 사용가능한 소스로 아래와 같이 수정했는데 getSize() 현재 API 버전에는 사용이 불가능하다고 나오더군요.

 

Call requires API level 13 (current min is 7): android.view.Display#getSize

 

 

Point pt = new Point();
getWindowManager().getDefaultDisplay().getSize(pt);
((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay().getSize(pt);
deviceHeight = pt.x;
deviceWidth = pt.y;

 

최종적으로 수정한 소스는 Context getResources().getDisplayMetrics() 호출하여 리턴받은 DisplayMetrics 객체에서 각각 widthPixels, heightPixels 사용하면 됩니다.

 

DisplayMetrics disp = getApplicationContext().getResources().getDisplayMetrics();
deviceWidth = disp.widthPixels;
deviceHeight = disp.heightPixels;
반응형
Posted by 녹두장군1
,