漂定

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
 1 /**
 2  * 手机分辨率转化类
 3  */
 4 package com.wu.mynews.util;
 5 
 6 import android.content.Context;
 7 
 8 public class DensityUtil {
 9     
10     /**
11      * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
12      * @param context
13      * @param dpValue
14      * @return
15      */
16     public static int dip2px(Context context,float dpValue){
17         final float scale = context.getResources().getDisplayMetrics().density;
18         return (int) (dpValue*scale+0.5f);
19     }
20     
21     /**
22      * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
23      * @param context
24      * @param pxValue
25      * @return
26      */
27     public static int px2dip(Context context,float pxValue){
28         final float scale = context.getResources().getDisplayMetrics().density;
29         return (int) (pxValue / scale + 0.5f);
30     }
31 
32 
33 }

 

posted on 2014-01-20 10:45  漂定  阅读(178)  评论(0编辑  收藏  举报