Android工具类--常用单位转换类
来源:互联网 发布:牛贝微信淘宝客安装 编辑:程序博客网 时间:2024/05/18 17:42
常用单位的转换
package com.duanlian;import android.content.Context;import android.util.TypedValue;/** * 常用单位转换的辅助类 */public class DensityUtils{private DensityUtils(){/* cannot be instantiated */throw new UnsupportedOperationException("cannot be instantiated");}/** * dp转px */public static int dp2px(Context context, float dpVal){return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,dpVal, context.getResources().getDisplayMetrics());}/** * sp转px */public static int sp2px(Context context, float spVal){return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,spVal, context.getResources().getDisplayMetrics());}/** * px转dp */public static float px2dp(Context context, float pxVal){final float scale = context.getResources().getDisplayMetrics().density;return (pxVal / scale);}/** * px转sp */public static float px2sp(Context context, float pxVal){return (pxVal / context.getResources().getDisplayMetrics().scaledDensity);}}
0 0
- Android工具类--常用单位转换类
- Android 单位转换工具类
- Android单位转换工具类
- 常用单位转换的工具类
- Android工具类之单位转换类
- Android大小单位转换工具类
- android学习笔记 单位转换工具类
- android长度单位转换工具类
- 《Android屏幕单位转换工具类》
- 安卓工具类------>常用单位转换的辅助类
- Android 单位转换工具
- Android中,单位dp、sp、px互相转换工具类
- Android工具类系列-DensityUtil(尺寸单位转换)
- Android 单位px、dp、sp转换工具类
- Android常用的验证及单位换算工具类
- Android常用辅助类之单位转换的辅助类
- Android DensityUtils-常用单位转换的辅助类
- Android中的常用单位转换
- Weex入门与进阶指南
- arm 知识
- 组合数/Lucas定理
- 水仙花数
- 给Android程序员的一些面试建议
- Android工具类--常用单位转换类
- HDU5007——Post Robot(2014 年 西安区域赛)
- AndroidManifest.xml常用标签解读
- MongoDB-C驱动的安装
- 【openCV入门之三】数据结构和绘图函数
- Hadoop单机部署文档
- 11.Java基础:常见IO流----->字节流中的对象流:ObjectIOutputStream、ObjectInputStream
- 单峰排列
- android-UI-viewpager--PagerTabStrip的使用---网易云探索(2)