I need to run different behavior based on screen size. So I got different types of the screens. If screen is small the variable in calculation must be 40. As it grows the variable number need to be decreased.
Example
Very Small screen width - 480 | variable = 40
Small screen width - 720 | variable = 30
Medium screen width - 1600 | variable = 20
Big screen width - 2560+ | variable = 10
Here is some of my code
val displayMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(displayMetrics)
val width = displayMetrics.widthPixels
val percentage = width / 100 * 10 //<----this 10 must be calculated dynamically
val rightBorder = width - percentage
when {
rawX.toInt() in 0..percentage -> {
params.x = 0
}
rawX.toInt() in rightBorder..width -> {
params.x = width
}