dp2px
fun dip2px(dpValue: Float): Int {
val scale = context!!.resources.displayMetrics.density
return (dpValue * scale + 0.5f).toInt()
}
fun Context.dp2px(dp: Float): Int {
// val displayMetrics = resources.displayMetrics
// return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT))
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.displayMetrics).toInt()
}
网友评论