1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
public
class
DensityUtil {
public
static
int
dip2px(Context context,
float
dpValue) {
final
float
scale = context.getResources().getDisplayMetrics().density;
return
(
int
) (dpValue * scale +
0
.5f);
}
public
static
int
px2dip(Context context,
float
pxValue) {
final
float
scale = context.getResources().getDisplayMetrics().density;
return
(
int
) (pxValue / scale +
0
.5f);
}
}
|
APP开发过程中Dp和Px之间的转换
最新推荐文章于 2022-10-10 10:54:33 发布