https://kotlinlang.org logo
Title
s

Sam

05/23/2021, 7:19 AM
Hello Good morning Im curious about 2 solutions convert
dp
to
px
Solution 1:
fun Int.dpToPx(context: Context): Int {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), context.resources.displayMetrics).toInt()
}
Solution 2:
fun Int.dpToPx() = (Resources.getSystem().displayMetrics.density * this + 0.5f)
so Which once is correct for multiple screen? Thanks.
m

Matteo Mirk

05/24/2021, 8:23 AM
looks more like an #android problem than a generic one on code conventions
s

Sam

05/24/2021, 8:24 AM
Ohm Thank @Matteo Mirk
👌 1