You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.0 KiB
41 lines
1.0 KiB
package com.project.survey.util;
|
|
|
|
import blankj.utilcode.util.Utils;
|
|
|
|
public class DisplayUtils {
|
|
/**
|
|
* dp 转成 px
|
|
* @return
|
|
*/
|
|
public static int dip2px(float dpVale) {
|
|
final float scale = (Utils.getApp()).getResources().getDisplayMetrics().density;
|
|
return (int) (dpVale * scale + 0.5f);
|
|
}
|
|
|
|
/**
|
|
* px 转 dp
|
|
* @return
|
|
*/
|
|
public static int px2dip(float pxValue) {
|
|
final float scale = (Utils.getApp()).getResources().getDisplayMetrics().density;
|
|
return (int) (pxValue / scale + 0.5f);
|
|
}
|
|
|
|
/**
|
|
* px 转 sp
|
|
* @return
|
|
*/
|
|
public static int px2sp(float pxValue) {
|
|
final float fontScale = (Utils.getApp()).getResources().getDisplayMetrics().scaledDensity;
|
|
return (int) (pxValue / fontScale + 0.5F);
|
|
}
|
|
|
|
/**
|
|
* sp 转 px
|
|
* @return
|
|
*/
|
|
public static int sp2px(float spValue) {
|
|
final float fontScale = (Utils.getApp()).getResources().getDisplayMetrics().scaledDensity;
|
|
return (int) (spValue * fontScale + 0.5F);
|
|
}
|
|
}
|
|
|