当前位置:网站首页>安卓kotlin sp dp转px
安卓kotlin sp dp转px
2022-06-22 20:05:00 【帅得不敢出门】
安卓kotlin sp dp转px
代码
/** * 根据手机的分辨率sp 转成px(像素) */
inline val Double.sp: Int get() = run {
toFloat().sp
}
inline val Int.sp: Int get() = run {
toFloat().sp
}
inline val Float.sp: Int get() = run {
val scale: Float = Resources.getSystem().displayMetrics.scaledDensity
return (this * scale + 0.5f).toInt()
}
/** * 根据手机的分辨率dp 转成px(像素) */
//使用示例 10.dp
inline val Double.dp: Int get() = run {
return toFloat().dp
}
inline val Int.dp: Int get() = run {
return toFloat().dp
}
inline val Float.dp: Int get() = run {
val scale: Float = Resources.getSystem().displayMetrics.density
return (this * scale + 0.5f).toInt()
}
边栏推荐
- 查询es分页下标超过1万
- Learning cloud network from teacher Tang - openstack network implementation
- 92 match for several_ Recognize SQL write example
- Watch,computed和methods的区别
- 300. 最长递增子序列 ●●
- One line of code binds swiftui view animation for a specific state
- 2022 question bank and simulated examination for work license of main principals of hazardous chemical business units
- 杰理之MUSIC 模式获取播放文件的目录【篇】
- Final review of scientific and technological literature of Shandong University (Personal Crash Course)
- MySQL adds (appends) prefix and suffix to a column field
猜你喜欢
随机推荐
Fegin的解析
第020讲:函数:内嵌函数和闭包 | 课后测试题及答案
2022化工自动化控制仪表考试练习题及在线模拟考试
ICML2022 | 利用虚拟节点促进图结构学习
2022危险化学品经营单位主要负责人上岗证题库及模拟考试
ACM. HJ24 合唱队 ●●
第014-15讲:字符串 (见小甲鱼新版27讲-32讲)| 课后测试题及答案
Watch,computed和methods的区别
Evaluation index and code realization (ndcg)
[redis]redis persistence
杰理之动态切换 EQ 文件【篇】
2022年山东省安全员C证考试试题模拟考试平台操作
Remote access to raspberry pie via the Internet.
万字长文 | 使用 RBAC 限制对 Kubernetes 资源的访问
杰理之开启四声道通话近端卡顿问题【篇】
苹果CoreFoundation源代码
Flutter System Architecture(Flutter系统架构图)
【OR36 链表的回文结构】
Apple GCD source code
php 镜像制作


![[redis]三种新数据类型](/img/ce/8a048bd36b21bfa562143dd2e47131.png)


![[20. valid brackets]](/img/e9/50f327048055b07b68e694a9003130.png)

![[redis] profile](/img/1c/05c06d59c9efb5983f877822db333c.png)
