Alex Rivera | Logout

How to Show Circular Text using TextView in Android

Asked 2012-10-31T07:31:33.687
17

I want to show text with circular shape in my android application.I know it is done with custome textview but can some buddy give me proper code.I am also attaching image which type of look i want.

enter image description here

Edit
Report

1 Answer

4

You have to create your own object "View" like this

public class YourView extends View {
    private static final String YOUR_TEXT = "something cool";
    private Path _arc;

    private Paint _paintText;

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

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

    }

    @Override
    protected void onDraw(Canvas canvas) {
      canvas.drawTextOnPath(YOUR_TEXT, _arc, 0, 20, _paintText);
      invalidate();
    }
}

and then use it as your TextView :) hope this help

answered 2012-11-06T12:02:31.897

Your Answer