본문 바로가기
프로그래밍/Android(Java)

[Android] 화면해상도 구하는 방법 (DPI)

by 쿼카퀀트 2019. 9. 29.
728x90

기기별로 해상도가 다르기 때문에, 화면 비율과 같이 크기가 변하는 View를 만들기 위해선 layout_weight를 써야한다. 하지만 코드에선 이를 쓰기 힘들기 때문에, 기기의DPI를 구한 후 그 값을 이용해 크기 조절을 한다.

 

//* 방법 1

Display dis=((WindowManager)getSystemService(Window_Service)).getDefaultDisplay();
DisplayMetrics metrix=new DisplayMetrics();
dis.getMetrics(metrix);


//* 방법 2

DisplayMetrics metrix=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrix);
728x90

댓글