Reputation: 1279
I have a custom view and I'm trying to draw a circle in the middle of the view. However the code produces an ellipse:
Paint p = new Paint();
p.setStyle(Style.STROKE);
p.setColor(Color.GREEN);
p.setStrokeWidth(0.02f);
mCanvas.drawCircle(0.5f, 0.5f, 0.2f, p);
The view width and height is the same as the darker round rectangle.
Upvotes: 0
Views: 152
Reputation: 1279
After a few tries, I figured out that it's because the width and height of the canvas were not equal. I had to scale the canvas to the same width/height. This is my code if anyone encounters the same problem:
mCanvas.save();
mCanvas.scale(1f, RATIO); //ratio between width and height
mCanvas.drawCircle(0.5f, 0.5f/RATIO, 0.2f, p);
mCanvas.restore();
Upvotes: 1