Android dp2px
来源:互联网 发布:国外域名注册价格对比 编辑:程序博客网 时间:2024/06/03 23:06
1
当我们在资源文件里设置尺寸的时候多是用dp,那么Android的开发并不局限于我们所用的资源文件,有时候我们需要动态的管理视图的尺寸,view给我们提供了setPadding(left, top, right, bottom);但是此时的
int
并不是dp,而是px,由自己来转换;下面给出转换的函数。
public static int px2dip(Context context, float pxValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); } public static int dip2px(Context context, float dpValue) {float scale = context.getResources().getDisplayMetrics().density;return (int) (dpValue * scale + 0.5f);}public static int dip2px(float dpValue) {Context context = MyApplication.getApplication();float scale = context.getResources().getDisplayMetrics().density;return (int) (dpValue * scale + 0.5f);}
0 0
- android dp2px
- Android dp2px
- Android初学-----px2dp,dp2px
- dp2px
- Android 为什么 dp2px 或 px2dp 公式需要加 0.5f
- Android 为什么 dp2px 或 px2dp 公式需要加 0.5f
- dp2px px2dp
- 图片旋转,压缩,保存,拷贝+dp2px
- Android
- android
- Android
- android
- android
- Android
- Android
- android
- android
- android
- 学习记录——2016年4月18日
- HDU 5665:Lucky【水】
- 动态规划算法整理
- 操作系统中常用的调度算法
- 如何对memcache的数据(key-value)进行遍历操作
- Android dp2px
- c#文本复制
- Java高级面试题积累(二)
- 如何使用Rally+Docker测试OpenStack
- 加速Android Studio的Gradle构建速度
- XStream使用总结
- SecureCRT乱码问题解决方法
- Maven常见问题
- HFC网络管理系统