화면 전체 크기를 구하고 싶은데요..
휴대폰 기종마다 네이게이션 바가 화면 크기에 포함되는 게 있고 안되는 게 있더라구요..
DisplayMetrics dm = new DisplayMetrics();
ctx.getWindowManager().getDefaultDisplay().getMetrics(dm);
return dm.heightPixels;
이렇게 구하니까.. 홈키가 화면에 포함된 휴대폰인 경우.. 홈 키 영역까지 다 합쳐서 크기를 구하더라구요.
결국 화면에 딱 맞지 않고 홈 키 높이만큼 더 커져서 나오던데요..
boolean isLandScape = ctx.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
int statusHeightId = ctx.getResources().getIdentifier("status_bar_height", "dimen", "android");
int statusHeight = 0;
if(statusHeightId > 0){
statusHeight = ctx.getResources().getDimensionPixelSize(statusHeightId);
}
int naviHeightId = ctx.getResources().getIdentifier("navigation_bar_height", "dimen", "android"); //landScape에서는 navigation_bar_height_landscape
int naviHeight = 0;
if (naviHeightId > 0) {
naviHeight = ctx.getResources().getDimensionPixelSize(naviHeightId);
}
int wholeSize = getDisplaySize(wm, false);
wholeSize -= statusHeight;
if(isLandScape == false){
wholeSize -= naviHeight;
}
return wholeSize;
그 다음 이 방법으로 해 봤는데 -_- .. 이것도 별로 차이가 없는 건지..
일반 휴대폰에서는 별 문제가 없는데, 스테이터스 바(상태표시줄)랑 네비게이션 바(홈키)가 같이 있는 태블릿에서 높이를 이상하게 구하는 거 같더라고요..
Rect rectangle = new Rect();
Window window = activity.getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
int statusBarTop = rectangle.top;
int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int statusbarHeight = Math.abs(statusBarTop - contentViewTop);
그 다음으로 시도해본 건 이 방법인데..
이건 OnGlobalLayoutListener로 업데이트 안해주니까... 값이 입력이 안되더라고요.
하 -_- 방법 없을까요..