drawTextOnPath drawing text round a circle using hoffset?
The following code should draw text 0 - 23 around a circle, as in a clock face. This is done by setting the hoffet parameter to drawTextOnPath. But it only works for the top half of the circle, why is this, is it a bug. In fact it prints 0 - 12 around the circle but the 2 of the twelve is also missing.
Path circle = new Path();
circle.addCircle(0, 0, (float) radius, Direction.CW);
Shape shape2 = new PathShape(circle, 1, 1);
shape2.resize(1, 1); // have to call this sets scaling
shape2.draw(canvas, timeFramePaint);
for (int hour=0; hour < 24; ++hour) {
// Text
drawHour(canvas, hour, radius, textPaint, circle);
}
public void drawHour(Canvas canvas, int hour, double radius,
Paint paint, Path path) {
Logger.getAnonymousLogger().info(String.valueOf(hour));
float hOffset = (float) (hour * radius * Constants.Tau / 24);
final float vOffset = 0;
canvas.drawTextOnPath(String.valueOf(ho开发者_运维问答ur), path, hOffset, vOffset, paint);
}
It appears to be a bug after doing some testing and looking at the sdk source code. I could be wrong but I don't see how it's useful by design.
Let's try to check size parent bitmap and size of circle. Here, I think may be the size of circle and parent bitmap size is the same. So text missing.
精彩评论