public final class DensityUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static int |
dp2px(android.content.Context context,
float dpValue)
根据手机的分辨率从 dp 的单位 转成为 px(像素)
|
static int |
dp2px(float dpValue)
根据手机的分辨率从 dp 的单位 转成为 px(像素)
|
static android.util.DisplayMetrics |
getDisplayMetrics()
DisplayMetrics
|
static int |
getRealDpi(android.content.Context context)
获取真实屏幕密度
|
static int |
getScreenDpi()
获取屏幕分辨率
|
static int |
px2dp(android.content.Context context,
float pxValue)
根据手机的分辨率从 px(像素) 的单位 转成为 dp
|
static int |
px2dp(float pxValue)
根据手机的分辨率从 px(像素) 的单位 转成为 dp
|
static int |
px2sp(android.content.Context context,
float pxValue)
根据手机的分辨率从 px(像素) 的单位 转成为 sp
|
static int |
px2sp(float pxValue)
根据手机的分辨率从 px(像素) 的单位 转成为 sp
|
static int |
sp2px(android.content.Context context,
float spValue)
根据手机的分辨率从 sp 的单位 转成为 px
|
static int |
sp2px(float spValue)
根据手机的分辨率从 sp 的单位 转成为 px
|
public static android.util.DisplayMetrics getDisplayMetrics()
public static int dp2px(float dpValue)
dpValue - 尺寸dippublic static int dp2px(android.content.Context context,
float dpValue)
context - 上下文dpValue - 尺寸dippublic static int px2dp(float pxValue)
pxValue - 尺寸像素public static int px2dp(android.content.Context context,
float pxValue)
context - 上下文pxValue - 尺寸像素public static int px2sp(float pxValue)
pxValue - 尺寸像素public static int px2sp(android.content.Context context,
float pxValue)
pxValue - 尺寸像素public static int sp2px(float spValue)
spValue - SP值public static int sp2px(android.content.Context context,
float spValue)
spValue - SP值public static int getScreenDpi()
public static int getRealDpi(android.content.Context context)
context - 上下文【注意,Application和Activity的屏幕密度是不一样的】