0

I want to show a text in the circle as a curve, so I wrote this code:

public class CircularTextView extends View {

private String text = "";
private Path circle;
private Paint tPaint;

int xAxis = 0, yAxis = 0;


public String getText() {
    return text;
}

public void setText(String text) {
    this.text = text;
}

private Path _arc;

private Paint _paintText;

public CircularTextView(Context context, int cx, int cy) {
    super(context);
    this.xAxis = cx;
    this.yAxis = cy;

    _arc = new Path();
    RectF oval = new RectF(xAxis,yAxis,0,yAxis/2);
    _arc.addArc(oval, 0, 180);
    _paintText = new Paint(Paint.ANTI_ALIAS_FLAG);
    _paintText.setStyle(Paint.Style.FILL_AND_STROKE);
    _paintText.setColor(Color.WHITE);
    _paintText.setTextSize(Functions.convertDpToPixel(16, context));
    _paintText.setTypeface(ResourcesCompat.getFont(context, R.font.quick_regular));

    setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawTextOnPath(getText(), _arc, xAxis/2, yAxis, _paintText);
    invalidate();
}

For using this custom class i have written this code.

 frameLayout.post(new Runnable() {
            @Override
            public void run() {

                int cx = frameLayout.getMeasuredWidth() / 2;
                int cy = frameLayout.getMeasuredHeight() / 2;

                CircularTextView circularTextView = new CircularTextView(FreddyChooseActivity.this, cx, cy);
                circularTextView.setLayoutParams(layoutParams);
                circularTextView.setText(choiceData.get(finalI).getChoiceName());

                frameLayout.addView(circularTextView);
            }
        });

above code is not working and it shows straight text not curved.

I want like this.

enter image description here

Advanced help would be appreciated!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Have you checked [this](https://stackoverflow.com/questions/13153201/how-to-show-circular-text-using-textview-in-android)? – tomerpacific Jul 03 '20 at 07:21
  • Yes I have checked this. But i has some static value for start , top, bottom and end position. I don't want to use it. I need my curve textview always be in center as i posted image. –  Jul 03 '20 at 07:23
  • If there is any library then it will be okay for me. @tomerpacific –  Jul 03 '20 at 07:25
  • @tomerpacific Any help?? –  Jul 03 '20 at 07:42
  • how about this? https://stackoverflow.com/a/30817342/10778405 – S T Jul 03 '20 at 08:04

0 Answers0