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