Android 在 API 级别 >= 8 中旋转 TextView [英] Android rotate TextView in API Level >= 8

查看:21
本文介绍了Android 在 API 级别 >= 8 中旋转 TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的 TextView

I have simple TextView

<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:rotation="45"
   android:text="Simple text" />

文本不会在 Android 2.2.2 上旋转 45 度.

The text wont be rotated to 45 degree on Android 2.2.2.

我看到了不同的线程,但每个人都在做动画.我不想动画.我想要的只是旋转文本视图.

I saw different threads, but everybody is doing an animation. I don't want to animate. All I want is to rotate the textview.

推荐答案

在 android 中对于任何新视图都有一个名为 setRotation(float) 你可以用它

In android for any new view there is a method called setRotation(float) you can use it

textview.setRotation(float);

但请注意,此方法是在 API 级别 11 中添加的

but please note that this method is Added in API level 11

所以如果你想支持它,你可以使用它

so if you want to support it you can use this

if (Build.VERSION.SDK_INT < 11) {

    RotateAnimation animation = new RotateAnimation(oldAngel, newAngel);
    animation.setDuration(100);
    animation.setFillAfter(true);
    textview.startAnimation(animation);
} else {

    textview.setRotation(progress);
}

这篇关于Android 在 API 级别 &gt;= 8 中旋转 TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆