android - Custom view draw circle produces elipse -
i have custom view , i'm trying draw circle in middle of view. code produces elipse:
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 , height same darker round rectangle.
after few tries, figured out it's because width , height of canvas not equal. had scale canvas same width/height. code if encounters same problem:
mcanvas.save(); mcanvas.scale(1f, ratio); //ratio between width , height mcanvas.drawcircle(0.5f, 0.5f/ratio, 0.2f, p); mcanvas.restore();
Comments
Post a Comment