我想以SeekBar
编程方式在画布上绘制一个。我编写了代码来设置SeekBar
基于设备密度的 LayoutParams。我正在使用具有设备密度的开关盒,例如
final DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
if(metrics.densityDpi <= DisplayMetrics.DENSITY_LOW){
zoomBarParams = new LinearLayout.LayoutParams(18,
LayoutParams.FILL_PARENT);
} else if (metrics.densityDpi <= DisplayMetrics.DENSITY_MEDIUM){
zoomBarParams = new LinearLayout.LayoutParams(24,
LayoutParams.FILL_PARENT);
}else if (metrics.densityDpi <= DisplayMetrics.DENSITY_HIGH){
zoomBarParams = new LinearLayout.LayoutParams(24,
LayoutParams.FILL_PARENT);
}else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XHIGH){
zoomBarParams = new LinearLayout.LayoutParams(31,
LayoutParams.FILL_PARENT);
}else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XXHIGH){
zoomBarParams = new LinearLayout.LayoutParams(60,
LayoutParams.FILL_PARENT);
}else if (metrics.densityDpi <= DisplayMetrics.DENSITY_XXXHIGH){
zoomBarParams = new LinearLayout.LayoutParams(60,
LayoutParams.FILL_PARENT);
} else {
zoomBarParams = new LinearLayout.LayoutParams(60,
LayoutParams.FILL_PARENT);
}
但这不适用于三星 Note 5、Galaxy S6 Edge 等高端设备。我相信这些设备的密度范围为 XXXHIGH,那么为什么这不起作用?在画布上绘图时,设备密度和屏幕尺寸之间有什么关系吗?任何帮助将不胜感激。