dp:根据屏幕密度进行适配
px:像素值
px–>dp
public static int px2dp(Context context,float pxValue){
//获得当前屏幕,获得屏幕原型,获得屏幕密度
float density = context.getResources().getDisplayMetrics().density;
return (int)(pxValue/density +0.5f);
}
dp–>px
public static int dp2px(Context context,float dpValue){
//获得当前屏幕,获得屏幕原型,获得屏幕密度
float density = context.getResources().getDisplayMetrics().density;
return (int)(dpValue*density +0.5f);
}