gpt4 book ai didi

java - 在 Android 中旋转文本(不是图像)

转载 作者:行者123 更新时间:2023-11-30 04:05:29 25 4
gpt4 key购买 nike

如何让文本(而不是图像)在 Android 中绕其轴旋转?

例子:

Enter image description here

最佳答案

您需要创建一个扩展 TextView 的类,然后覆盖 onDraw 方法,如下所示:

public class MyRotatedTextView extends TextView {

...

@Override
protected void onDraw(Canvas canvas) {
canvas.save();

float py = this.getHeight() / 2.0f;
float px = this.getWidth() / 2.0f;
canvas.rotate(180, px, py);

super.onDraw(canvas);

canvas.restore();
}
}

在这种情况下,旋转轴穿过 TextView 的中心。

关于java - 在 Android 中旋转文本(不是图像),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11742662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com