전역에서 안드로이드 해상도를 가지고있으면 좋다
var resolutionWitdh = 0
var resolutionHeight = 0
private fun getScreenResolution(context: Context) {
val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val display = wm.defaultDisplay
val metrics = DisplayMetrics()
display.getMetrics(metrics)
resolutionWitdh = metrics.widthPixels
resolutionHeight = metrics.heightPixels
}
나중에 ui 작업할 때 비율에 맞게 작업해줄 수 있기 때문에
Log.d("TEST RESOLUTION", getScreenResolution(this))
val screenSize =
resources.configuration.screenLayout and SCREENLAYOUT_SIZE_MASK
val toastMsg: String
toastMsg = when (screenSize) {
SCREENLAYOUT_SIZE_LARGE -> "Large screen"
SCREENLAYOUT_SIZE_NORMAL -> "Normal screen"
SCREENLAYOUT_SIZE_SMALL -> "Small screen"
else -> "Screen size is neither large, normal or small"
}
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show()
타블릿인지 아닌지 판별한다
private fun isTablet(): Boolean {
val xlarge =
resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK == 4
val large =
resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK == Configuration.SCREENLAYOUT_SIZE_LARGE
return xlarge || large
}