我嘗試使用方法drawCircle(...)在Canvas的幫助下創建一個圓。但最終爲什麼讓我成爲一個橢圓而不是一個圓?我怎樣才能得到「真實」的圈子?Android Canvas.drawCircle()錯誤。持續繪製橢圓而不是圓形
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(服務)
嘗試使用'setImageBitmap()'而不是'setBackgroundDrawable()' – Vikram
謝謝,這對我有幫助。請做你的評論作爲答案 - 我會投票(最佳答案)。 –
感謝Siruk,很高興我能幫上忙。 – Vikram