android dp和px之间转换
16lz
2021-01-24
public class DensityUtil { /** * 根据手机的分辨率从 dip 的单位 转成为 px(像素) */ public static int dip2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } /** * 根据手机的分辨率从 px(像素) 的单位 转成为 dp */ public static int px2dip(Context context, float pxValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
更多相关文章
- android 中根据两个经纬度计算两地距离
- android px转换为dip/dp
- Android(安卓)Launcher 之 图标加框 优化显示效果
- android mediareorder 使用实践总结
- android主流分辨率
- android,ios app icon 应用图标大小/尺寸
- [Android]-图片JNI(C++\Java)高斯模糊的实现与比较
- 关于android分辨率兼容(屏幕适配)问题
- Android游戏Graphics绘图之图像像素操作