Fork me on GitHub

Android开发之dp转像素,像素转换为dp工具类,详细代码,带有源文件下载地址。

import android.content.Context;
/** 
 * @author 官网:http://blog.csdn.net/qq_21376985
 *  
 *         David编写: 微博:http://weibo.com/93sec.cc 
 *  
 * @version V1.0正式版 
 *  
 * @process QQ986945193 
 *  
 * @Note weibo.com/mcxiaobing 
 *  
 * @dateTime 2015-10-18下午1:46:20 
 *  
 */  
public class DensityUtil {
	/**
	 * dip转像素
	 */
	public static int dip2px(Context context, float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}

	/**
	 * 像素转dip
	 */
	public static int px2dip(Context context, float pxValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);
	}
}


源代码免费下载地址:http://download.csdn.net/detail/qq_21376985/9514354

posted @ 2016-05-09 13:53  程序员小冰  阅读(223)  评论(0编辑  收藏  举报


Fork me on GitHub