How to write curved text? [closed]
Asked Answered
G

2

22

I want to write curved text like this:

curved text

How can I do this?

Gnarled answered 1/12, 2011 at 6:8 Comment(0)
S
35

Lol, this is fun, I've just tried to make a text curve, you can try it:

package pete.android.study;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;

import android.graphics.RectF;
import android.view.View;

public class GraphicsView extends View {
    private static final String MY_TEXT = "xjaphx: Draw Text on Curve";
    private Path mArc;

    private Paint mPaintText;

    public GraphicsView(Context context) {
      super(context);     

      mArc = new Path();
      RectF oval = new RectF(50,100,200,250);;
      mArc.addArc(oval, -180, 200);          
      mPaintText = new Paint(Paint.ANTI_ALIAS_FLAG);
      mPaintText.setStyle(Paint.Style.FILL_AND_STROKE);
      mPaintText.setColor(Color.WHITE);
      mPaintText.setTextSize(20f);

    }

    @Override
    protected void onDraw(Canvas canvas) {
      canvas.drawTextOnPath(MY_TEXT, mArc, 0, 20, mPaintText);      
      invalidate();
    }
  }
Season answered 1/12, 2011 at 7:43 Comment(0)
I
4

Sounds like you want to draw text on a path. Therefore you should create a path that is an Arc and then draw the text on it and that should work perfectly. I hope that helps.

Indurate answered 1/12, 2011 at 6:15 Comment(1)
But i m not having x, y......what to do?Gnarled

© 2022 - 2024 — McMap. All rights reserved.