DP to Pixel

필요할 때마다 매번 찾기 귀찮아서 보관

Function with parameters

fun dpToPx(context: Context, dp: Int): Int {
    val dencity = context.resources.displayMetrics.density
    return (dp.toFloat() * density).roundToInt()
}

Extension Function

fun Int.dpToPx(): Int {
    val dencity = context.resources.displayMetrics.density
    return (this.toFloat() * density).roundToInt()
}

Leave a Comment

Your email address will not be published. Required fields are marked *