wxr
2020-06-15 b8e94316e41eba72d927d5ca7d931b26139ee8ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);  
        }  
    }  
}