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);      }  }

版权声明:本文为博主原创文章,未经博主允许不得转载。

更多相关文章

  1. android 中根据两个经纬度计算两地距离
  2. android px转换为dip/dp
  3. Android(安卓)Launcher 之 图标加框 优化显示效果
  4. android mediareorder 使用实践总结
  5. android主流分辨率
  6. android,ios app icon 应用图标大小/尺寸
  7. [Android]-图片JNI(C++\Java)高斯模糊的实现与比较
  8. 关于android分辨率兼容(屏幕适配)问题
  9. Android游戏Graphics绘图之图像像素操作

随机推荐

  1. 这么用 if-else,小鹿差点被辞退!
  2. centos 用户权限管理与文件权限设定 详
  3. 60 天呕心沥血,我写完这本电子书!
  4. 鹿哥带读者做外包,它香吗?
  5. TensorFlow 零基础入门指南
  6. 一文搞定pandas的数据合并
  7. 性能优化 | 实战中几点性能优化方案!
  8. 自学第五十四天
  9. 谈谈“偶像崇拜”的危害!
  10. 2021.1.20