Sam
05/24/2021, 8:24 AMdp
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.louiscad
05/24/2021, 9:20 AMephemient
05/24/2021, 9:23 AMlouiscad
05/24/2021, 9:24 AMephemient
05/24/2021, 9:25 AMephemient
05/24/2021, 9:26 AMephemient
05/24/2021, 9:26 AMephemient
05/24/2021, 9:27 AMSam
05/24/2021, 10:11 AM