android手机dp与px转换工具类
来源:互联网 发布:手机淘宝怎么改店铺名 编辑:程序博客网 时间:2024/04/29 09:32
android手机dp与px转换工具类
public final class DensityUtil { private static float density = -1F; private static int widthPixels = -1; private static int heightPixels = -1; private DensityUtil() { }//获取屏幕密度(获得的不是真实的屏幕密度,而是相对于某个值的屏幕密度,应该是密度的一个比例) public static float getDensity() { if (density <= 0F) { density = x.app().getResources().getDisplayMetrics().density; } return density; }//dp转px,0.5f是因为强制转换成int时候要四舍五入 public static int dip2px(float dpValue) { return (int) (dpValue * getDensity() + 0.5F); }//px转dp,0.5f是因为强制转换成int时候要四舍五入 public static int px2dip(float pxValue) { return (int) (pxValue / getDensity() + 0.5F); }//获取屏幕宽度单位px(像素) public static int getScreenWidth() { if (widthPixels <= 0) { widthPixels = x.app().getResources().getDisplayMetrics().widthPixels; } return widthPixels; }//获取屏幕高度单位px(像素) public static int getScreenHeight() { if (heightPixels <= 0) { heightPixels = x.app().getResources().getDisplayMetrics().heightPixels; } return heightPixels; }}
0 0
- android手机dp与px转换工具类
- dp与px转换工具类
- dp与px转换工具类
- Android 常见手机dp与px之间的转换
- # android中dp与px的相互转换工具方法
- Android px与dp转换
- dp, sp, 与 px 互相转换的工具类
- 工具类--DensityUtil dp与px的相互转换
- android中dp和px之间转换的工具类
- Android中,单位dp、sp、px互相转换工具类
- Android中dp和px之间进行转换(工具类)
- Android 单位px、dp、sp转换工具类
- Android dp、sp转换为px的工具类
- Android工具类---dp,px,sp之间的转换
- Android dp、sp 转换为 px 的工具类
- Android——工具类(屏幕尺寸、sp转换为px、dp转换为px)
- dp,px,sp单位转换工具类
- px,dp,sp转换工具类
- 蓝桥杯练习系统 拿糖果
- JS跨域:No 'Access-Control-Allow-Origin' header is present on the requested resource
- Java.util.concurrent之 Executor框架与线程池
- Android CookieSyncManager同步cookie
- hadoop-2.6.0安装
- android手机dp与px转换工具类
- linux中inode的工作原理
- Cordova构建Android,IOS工程实例
- Android Studio和Idea使用svn的patch包
- [RK3288][Android6.0] 调试笔记 --- 实时录音会有呲呲噪音问题
- find_first_of();find_last_of();find();
- 移动开发网络杂谈
- Unity3DGame学习笔记:背包系统(homework10)
- Nginx的启动、暂停、重启命令