android - 在 Canvas 中旋转文本

标签 android text rotation android-canvas

如何旋转 Canvas 中的文本?我需要翻转我颠倒的文字。

paint.setTextSize(20); 
canvas.drawText("3AM", xStored, yStored, paint);

最佳答案

引用这个link

 int x = 75;
    int y = 185;
    paint.setColor(Color.GRAY);
    paint.setTextSize(25);
    String rotatedtext = "Rotated helloandroid :)";

    //Draw bounding rect before rotating text:

    Rect rect = new Rect();
    paint.getTextBounds(rotatedtext, 0, rotatedtext.length(), rect);
    canvas.translate(x, y);
    paint.setStyle(Paint.Style.FILL);

    canvas.drawText(rotatedtext , 0, 0, paint);
    paint.setStyle(Paint.Style.STROKE);
    canvas.drawRect(rect, paint);

    canvas.translate(-x, -y);


    paint.setColor(Color.RED);
    canvas.rotate(-45, x + rect.exactCenterX(),y + rect.exactCenterY());
    paint.setStyle(Paint.Style.FILL);
    canvas.drawText(rotatedtext, x, y, paint);

关于android - 在 Canvas 中旋转文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20572572/

相关文章:

android - 如何通过 Activity 的取消按钮强制 IntentService 立即停止?

java - 没有首选/最大/最小尺寸的文本包装 JLabel

Python libxml2 : querying xml using xpath

python - 在最后 2 个维度中旋转 5D 数组

java - 在圆上绘制点

android - 如何修复以下错误 : A problem occurred evaluating project ':app' . > 没有方法签名:

java - 由于 If 语句导致代码崩溃

python - 如何有效地将方形 numpy 数组旋转不同时间 `np.rot90` ?

android - gradle中依赖项的动态版本(使用+)

c++ - 来自文本文件的数据总和