Hello Good morning Im curious about 2 solutions co...
# codingconventions
s
Hello Good morning Im curious about 2 solutions convert
dp
to
px
Solution 1:
Copy code
fun Int.dpToPx(context: Context): Int {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), context.resources.displayMetrics).toInt()
}
Solution 2:
Copy code
fun Int.dpToPx() = (Resources.getSystem().displayMetrics.density * this + 0.5f)
so Which once is correct for multiple screen? Thanks.
m
looks more like an #android problem than a generic one on code conventions
s
Ohm Thank @Matteo Mirk
👌 1