-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Open
Labels
Description
- AndroidUtilCode 的版本:1.31.1
- 出现 Bug 的设备型号:所有型号
- 设备的 Android 版本:所有版本
描述 Bug
SizeUtils中 因为尺寸转换是以系统的像素密度来处理的
Resources.getSystem().getDisplayMetrics().density;
在那些通过修改activity像素密度来适配的应用里, 转换会产生严重误差
context.getResources().getDisplayMetrics().density;
是否可以增加一个通过上下文来转换尺寸的方法
如下
相关代码
public static int dp2px(final float dpValue) {
final float scale = Resources.getSystem().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
} public static int dp2px(Context context, float dipValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}Reactions are currently unavailable