Android Canvas.drawCircle()错误。持续绘制椭圆而不是圆形

时间:2013-07-17 11:02:13

标签: java android android-canvas geometry

我尝试使用drawCircle(...)方法在Canvas的帮助下创建一个圆圈。但最终为什么要给我一个椭圆而不是一个圆?我怎样才能得到“真正的”圈子?

Bitmap bitmap = Bitmap.createBitmap((int) (widthView), heightView, Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  paint.setColor(Color.parseColor("#FF950000"));
  paint.setAntiAlias(true);
  paint.setStyle(Style.FILL);
  canvas.drawRect(0.0f, 0.0f, widthView, heightLevel, paint);
  paint.setColor(Color.parseColor("#FFD4A503"));
  canvas.drawRect(0.0f, heightLevel, widthView, 2 * heightLevel, paint);
  paint.setColor(Color.parseColor("#FF4A7816"));
  canvas.drawRect(0.0f, 2 * heightLevel, widthView, 3 * heightLevel,
    paint);
  paint.setColor(Color.parseColor("#FFFFFFFF"));
  canvas.drawCircle(30 * density, getLevelHeight(1), 20f, paint);  graphicView.setBackgroundDrawable(new BitmapDrawable(getResources(),
    bitmap));

结果:

Nexus 4

enter image description here

华为G500Pro(Shine)

enter image description here

1 个答案:

答案 0 :(得分:0)

您应该使用setImageBitmap(Bitmap)代替setBackgroundDrawable()

此外,setBackgroundDrawable()已被弃用。