當(dāng)前位置:
首頁(yè) >
DP PX转换
發(fā)布時(shí)間:2025/4/5
31
豆豆
/*** 文件:DensityUtil* 時(shí)間:2018/8/15.* 備注:單位換算*/public class DensityUtil {/*** 根據(jù)手機(jī)的分辨率從 dp 的單位 轉(zhuǎn)成為 px(像素)*/public static int dip2px(Context context, float dpValue) {final float scale = context.getResources().getDisplayMetrics().density;return (int) (dpValue * scale + 0.5f);}/*** 根據(jù)手機(jī)的分辨率從 px(像素) 的單位 轉(zhuǎn)成為 dp*/public static int px2dip(Context context, float pxValue) {final float scale = context.getResources().getDisplayMetrics().density;return (int) (pxValue / scale + 0.5f);}
}
總結(jié)
- 上一篇: Kotlin中的接口回调
- 下一篇: 基于 Kotlin 一行代码实现 and