Skip to content

Commit

Permalink
dp扩展
Browse files Browse the repository at this point in the history
  • Loading branch information
br3ant committed Sep 19, 2020
1 parent 228ddea commit c008767
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions utils/src/main/java/com/br3ant/utils/Dp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.br3ant.utils

import android.content.res.Resources
import android.util.TypedValue

/**
* <pre>
* copyright: datedu
* @author : br3ant
* e-mail : xxx@xx
* time : 2020/9/19
* desc :
* version: 1.0
* </pre>
*/

val Float.dp
get() = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
this,
Resources.getSystem().displayMetrics
)
val Int.dp: Int
get() {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
this.toFloat(),
Resources.getSystem().displayMetrics
).toInt()
}

0 comments on commit c008767

Please sign in to comment.