11

I have simple TextView

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

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.

Zbarcea Christian
  • 9,367
  • 22
  • 84
  • 137
  • 3
    subclass textview and override onDraw. It is really simple – Blackbelt Nov 07 '13 at 10:47
  • In addition to 'blackbelt' response you can check example here http://stackoverflow.com/questions/9262494/draw-text-vertically-on-canvas – Yahya Arshad Nov 07 '13 at 10:51
  • follow this tutorial http://eleanordarephdjournal.blogspot.in/2011/03/another-good-android-example-with.html –  Nov 07 '13 at 10:52

2 Answers2

18

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

textview.setRotation(float);

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);
}
Simon K. Gerges
  • 3,097
  • 36
  • 34
  • setRotation() in java equals to rotation in xml, and they are both rotate the whole TextView, but not the text in the TextView. – twlkyao Feb 25 '16 at 02:27
3

I found "android:rotation" is not work in SDK 21,in other words is Android 5.0. But i just found this problem in layout preview, not test in really device.

Snow Albert
  • 547
  • 7
  • 15