我有一个循环油画创建一个圆圈,所有工作但在不同的设备上我得到不同的油漆尺寸,我认为这是一个密度问题,我该如何解决问题?
这是我的代码:
for(int i=0; i<360; i = i + 12){
x = (float) (view.getWidth()/2 + raggio_in * Math.cos(Math.toRadians(i)));
y = (float) (view.getHeight()/2 + raggio_in * Math.sin(Math.toRadians(i)));
Paint paint = new Paint();
paint.setFlags(Paint.ANTI_ALIAS_FLAG);
paint.setColor(getResources().getColor(R.color.tutorial_text));
if(i < progress){
paint.setColor(Color.WHITE);
}
canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.rotate(i, x, y);
canvas.drawRoundRect(new RectF((float) x-deltaX, (float) y-deltaY, (float) x+deltaX, (float) y+deltaY), raggio_elemento, raggio_elemento, paint);
canvas.restore();
x = (float) (view.getWidth()/2 + raggio_out * Math.cos(Math.toRadians(i)));
y = (float) (view.getHeight()/2 + raggio_out * Math.sin(Math.toRadians(i)));
paint = new Paint();
paint.setColor(getResources().getColor(R.color.tutorial_text));
if(i < progress){
paint.setColor(Color.WHITE);
}
canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.rotate(i, x, y);
canvas.drawRoundRect(new RectF((float) x-deltaX, (float) y-deltaY, (float) x+deltaX, (float) y+deltaY), raggio_elemento, raggio_elemento, paint);
canvas.restore();
}
答案 0 :(得分:0)
您可以用dp
这种方式计算维度:
pixels * density + 0.5f
density
可以访问context.getResources().getDisplayMetrics().density
0.5f
用于舍入