手机分辨率dp和px转换
2015-08-31 15:35
417 查看
public class DensityUtil { /** * 根据手机的分辨率从 dp 的单位 转成为 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); } }
相关文章推荐
- HDU1008 - Elevator (简单模拟)
- Java IO体系中常用的流分类
- 运行命令集锦
- CMU & Stanford 课程
- 内存管理
- [LeetCode]: 104: Maximum Depth of Binary Tree
- form表单,submit,ajax提交
- PHP中 array_map 与 array_column 之间的关系
- raspbian 配置AP热点
- Android Gradle配置自动生成JavaDoc
- 关于苹果的IDFA(广告识别符)政策
- ALTERA DE2 之 verilog HDL 学习笔记03 FPGA的PWM输出
- sqlplus64: error while loading shared libraries: libsqlplus.so 解决
- 图片选择jsp和png
- 逐梦路上,坚定信念
- Android开发:shape和selector和layer-list的(详细说明)
- 点击按钮下载文件
- 这种东西Skype莫名啟動
- fragment应用实例二
- shiro—安全配置