상세 컨텐츠

본문 제목

Android 안드로이드 개발 Screen Size Inch(인치) 구하기 관련

스마트기기개발관련/안드로이드 개발

by AlrepondTech 2015. 12. 11. 16:24

본문

반응형
728x170


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


출처: http://lsit81.tistory.com/116


Android에서 제공되는 DisplayMetrix의 정의된 상수를 살펴보면 아래와 같이 되어 있습니다. 





여기서 보셔야할 상수는 xdpi 와 ydpi 입니다. 

이 상수는 The exact physical pixels per inch of the screen 이라고 정의되어 있습니다. 


그렇기 때문에 이것을 적절히 이용하면 스크린의 Inch값을 구할 수 있습니다. 


소스는 아래와 같습니다. 

* 소수점 1번째 자리까지 이용하시면 꽤 정확한 Inch가 나타납니다. 

1
2
3
4
5
6
7
8
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
 
double x = Math.pow(dm.widthPixels/dm.xdpi,2);
double y = Math.pow(dm.heightPixels/dm.ydpi,2);
double screenInches = Math.sqrt(x+y);
 
Log.d("TEST","Screen inches : " + screenInches);



출처 : http://stackoverflow.com/questions/6589101/how-to-get-screen-size-of-device





//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


출처: http://lhh3520.tistory.com/128



 가로의 인치와 세로의 인치를 구해서 가로,세로 의 대각선의 길이를 구하면 대략적으로
화면의 인치를 구할 수 있다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public double GetMyDeviceInch()
{
     DisplayMetrics matrix = new DisplayMetrics();
     getWindow().getWindowManager().getDefaultDisplay().getMetrics(matrix);
              
     int w = matrix.widthPixels;
     int h = matrix.heightPixels;
     float xdpi = matrix.xdpi;
     float ydpi = matrix.ydpi;
     float x_inch = w/xdpi;
     float y_inch = h/ydpi;
     double display = Math.sqrt(x_inch*x_inch+y_inch*y_inch);
     return display;
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

반응형
그리드형


관련글 더보기

댓글 영역