Как повернуть текст, нарисованный с помощью canvas.drawTextOnPath ()? - PullRequest
0 голосов
/ 24 января 2020

Я использую drawTextOnPath (), чтобы создать изогнутый текст, как показано на рисунке ниже, но я не могу понять, как вращать текст?

То, что я хочу, выделено ниже на рисунке стрелкой и кружком .

enter image description here

То, что мне удалось достичь, ниже

enter image description here

То есть я просто хочу повернуть эти тексты?

Ответы [ 2 ]

0 голосов
/ 05 марта 2020

Вам просто нужно перевернуть холст и нарисовать на нем

canvas.save()
canvas.scale(1, -1, width / 2, height / 2)
// your drawing code
canvas.restore()
0 голосов
/ 28 января 2020

Вы можете достичь желаемого результата без drawTextOnPath (), используя:

        float radius = 300;
        float cx = getWidth() / 2; //Center of the circle
        float cy = getHeight() / 2; //Center of the circle

        for (int degree = 0; degree < 360; degree += 30) {
            canvas.save();
            canvas.translate(cx, cy);
            canvas.rotate(degree);
            String text = "" + degree;
            float textCenterX = radius + textPaint.measureText(text) / 2;
            float textCenterY = 0 - textPaint.getTextSize() / 2;
            if (degree < 180) {
                canvas.rotate(-90, textCenterX, textCenterY);
            } else {
                canvas.rotate(+90, textCenterX, textCenterY);
            }
            canvas.drawText("" + degree, radius, 0, textPaint);
            canvas.restore();
        }

enter image description here

...