我尝试使用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
华为G500Pro(Shine)
答案 0 :(得分:0)
您应该使用setImageBitmap(Bitmap)
代替setBackgroundDrawable()
。
此外,setBackgroundDrawable()
已被弃用。