android - 应用于文本的方法 canvas.rotate(90) 对于 android 4.0-4.1 已损坏

标签 android rotation textview

我尝试使用 canvas.rotate() 方法使文本垂直。但是在 android 4.0 - 4.1 上我得到了一个“跳舞的字母”,见截图。发生了什么事,我该如何解决?请帮助我。

4.0 - 4.1 结果:

enter image description here

正常结果:

enter image description here

这是代码

 @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint textPaint = new Paint();
        textPaint.setColor(Color.WHITE);
        textPaint.setTextSize(30);
        canvas.rotate(90);
        canvas.drawText(text, 0, -getWidth()/2, textPaint);
        canvas.save();
        canvas.restore();
    }

最佳答案

简单地说,您可以尝试一下并且:

使用 textView 并在其上设置 rotateAnimatesetDuration 最小值并设置 setFillAfter(true) 如下所示:

  RotateAnimation rt = new RotateAnimation(0, 90,textView.getLayoutParams().width/2,textView.getLayoutParams().height/2);
  rt.setDuration(1);                
  rt.setFillAfter(true);
  textView.startAnimation(rt);

很简单

关于android - 应用于文本的方法 canvas.rotate(90) 对于 android 4.0-4.1 已损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14379909/

相关文章:

objective-c - 带旋转的 MKAnnotationView 图像

c# - unity C# 四元数旋转校正方向

java - Android:TextView,unicode 字符未正确显示

textview - 您可以将倒计时器放入片段中吗?

android - OpenGL ES 1.1 将两个纹理合并为一个可重复使用的纹理

android - 在 Android 上将 SQL 数据库与 REST 远程服务器同步的最佳实践

ios - 当我们开始旋转设备时和完成后将调用什么方法

android - 在辅助功能模式下,我想覆盖 TextView 的 TalkBack

android - 我应该在所有地方为所有小部件使用 Roboto 字体吗?

android - 导出字符串时出错