val Int.dp: Float get()= this.toFloat().dp
val Int.dpi: Int get() = this.toFloat().dpi
val Float.dp: Float get(){
val displayMetrics: DisplayMetrics = Resources.getSystem().displayMetrics
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this, displayMetrics)
}
val Float.dpi: Int get(){
val displayMetrics: DisplayMetrics = Resources.getSystem().displayMetrics
return (this * displayMetrics.density).toInt()
}
用法:6.dp