using System;
namespace Shared
{
internal static class DensityUtil {
///
/// 根据手机的分辨率从 dp 的单位 转成为 px(像素)
///
/// The px.
/// Dp value.
public static int Dip2Px(float dpValue) {
float scale = Application.Activity.Resources.DisplayMetrics.Density;
// scale = context.Resources.DisplayMetrics.Density;
return (int) (dpValue * scale + 0.5f);
}
///
/// 根据手机的分辨率从 px(像素) 的单位 转成为 dp
///
/// The dip.
/// Px value.
public static int Px2Dip(float pxValue) {
float scale = Application.Activity.Resources.DisplayMetrics.Density;
return (int) (pxValue / scale + 0.5f);
}
}
}