back 버튼이 있는 부분을 포함해서 해상도를 가져와야한다.
/** * 스크린 너비 */ fun fullScreenWidth(): Int { return fullScreenSize().first } /** * 스크린 높이. 하단 back 버튼이 있는 뷰의 높이 포함 */ fun fullScreenHeight(): Int { return fullScreenSize().second } /** * 전체 스크린 사이즈. 하단 back 버튼이 있는 뷰의 높이 포함 */ fun fullScreenSize(): Pair<Int, Int> { val metrics = DisplayMetrics() when { Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 -> { context.display?.getRealMetrics(metrics).apply { return Pair(metrics.widthPixels, metrics.heightPixels) } } else -> { val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager windowManager.defaultDisplay.getMetrics(metrics) var bottomBarHeight = 0 context.resources.getIdentifier("navigation_bar_height", "dimen", "android").apply { if (this > 0) { bottomBarHeight = context.resources.getDimensionPixelSize(this) } } return if (Configuration.ORIENTATION_LANDSCAPE == context.resources.configuration.orientation) { Pair(metrics.widthPixels + bottomBarHeight, metrics.heightPixels) } else { Pair(metrics.widthPixels, metrics.heightPixels + bottomBarHeight) } } } }
낮은 버전까지 신경쓰려니 무지 귀찮구만 ㅠㅠ