I’m using the following to draw rounded-corner rectangles in my Android application and it seems to be working alright but with one minor problem:
// Draw the control buttons
paint.setColor (Color.DKGRAY);
paint.setStyle (Style.FILL);
canvas.drawRoundRect (zPlusRectF, 12, 12, paint);
canvas.drawRoundRect (zMinusRectF, 12, 12, paint);
paint.setColor (Color.LTGRAY);
paint.setStyle (Style.STROKE);
canvas.drawRoundRect (zPlusRectF, 12, 12, paint);
canvas.drawRoundRect (zMinusRectF, 12, 12, paint);
paint.setColor (Color.WHITE);
paint.setStyle (Style.FILL);
paint.setTextSize (BUTTON_TEXT_SIZE);
... (Adding labels to the rectF's defined above follows) ...
The strange thing is that the two ends of the rectangle aren’t rounded over the same. The left-side quarter circles are noticeably smaller than the ones on the right.
Anybody experienced anything similar? It’s weird enough that I might change my mind about the round corners if I can’t do anything about it…. And if I knew how to do a screen capture from my Android, I would.
Thanks,
R.
Edit: The rectangles in question are 78 pixels wide and 48 tall, if that helps (and since ykatchou may be onto something).
The problem turned out to be a function of anti-aliasing. When you’re drawing 2D graphics in Android (and probably elsewhere, too), and rule of thumb that works out for me is:
Turn anti-aliasing on for curves and text, but off for straight lines.
Once I paid attention to managing the anti-aliasing state in my drawing methods, this problem was fixed.