我想画时钟的弯曲文字。到目前为止,我只是屈服于弯曲。
public class TextDrawActivity extends AppCompatActivity {
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new TextDrawingView(this));
}
static class TextDrawingView extends View {
private Path arc;
private RectF bounds;
private TextPaint textPaint;
public TextDrawingView(Context context) {
super(context);
arc = new Path();
bounds = new RectF();
textPaint = new TextPaint();
textPaint.setAntiAlias(true);
textPaint.setTextSize(50);
textPaint.setColor(Color.BLACK);
}
@Override public void draw(Canvas canvas) {
super.draw(canvas);
bounds.set(0f, 0f, getWidth() * 0.8f, getHeight() / 2.f);
arc.rewind(); // Clear internal structure.
arc.addArc(bounds, 45, 360);
canvas.drawTextOnPath("Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
arc, 0, textPaint.getTextSize() / 2.f, textPaint);
}
}
}
使用此代码,它看起来像这样:
我如何以时钟方式绘制文本,以便它不再被颠倒?
答案 0 :(得分:1)
在评论中回答pskink时,可以使用否定sweepAngle
来实现此效果:
@Override public void draw(final Canvas canvas) {
super.draw(canvas);
bounds.set(0f, 0f, getWidth() * 0.8f, getHeight() / 2.f);
arc.rewind(); // Clear internal structure.
arc.addArc(bounds, 135, -180);
canvas.drawTextOnPath("Lorem ipsum dolor sit amet, consectetur adipisicing elit.", arc, 0, textPaint.getTextSize() / 2.f, textPaint);
}