android字体开发pd,android中px与pd的转换

package com.google.example.utils;

import android.content.Context;

/**

* px和dp互相转换工具

*/

public class DensityUtil {

/**

* 根据手机的分辨率从 dip 的单位 转成为 px(像素)

*/

public static int dip2px(Context context, float dpValue) {

final float scale = context.getResources().getDisplayMetrics().density;

return (int) (dpValue * scale + 0.5f);

}

/**

* 根据手机的分辨率从 px(像素) 的单位 转成为 dp

*/

public static int px2dip(Context context, float pxValue) {

final float scale = context.getResources().getDisplayMetrics().density;

return (int) (pxValue / scale + 0.5f);

}

}

点赞 (0)赏分享 (0)

相关资源:诗词鉴赏大全软件-教育文档类资源-CSDN文库

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年4月22日
下一篇 2021年4月22日

相关推荐