Android 中像素px和dp的转化的代码

把开发过程中经常用的代码段备份一次,下面的代码段是关于Android 中像素px和dp的转化的代码。

public int Dp2Px(Context context, float dp) {
final float scale = context.getResources().getDisplayMetrics().density;
}

public int Px2Dp(Context context, float px) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (px / scale + 0.5f);
}

猜你喜欢

转载自blog.csdn.net/weixin_44314274/article/details/85321139
今日推荐