逆时针而不是顺时针绘制弯曲的文本
Drawing curved text counter clock wise instead clock wise
我想逆时针绘制弯曲的文本。到目前为止,我只做到了弯曲。
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);
}
}
}
使用这段代码,它看起来像这样:
如何逆时针绘制文本,使其不再颠倒?
正如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);
}
我想逆时针绘制弯曲的文本。到目前为止,我只做到了弯曲。
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);
}
}
}
使用这段代码,它看起来像这样:
如何逆时针绘制文本,使其不再颠倒?
正如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);
}