Sideways View with XML Android

There is, but it’s new in API 11 (Android 3.0):

<TextView
    android:id="@+id/rotated"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:rotation="270"
    android:textSize="32sp"
    android:textColor="#44CC44"
    android:text="@string/rotated" />

I tried this in 2.2, 2.3.1, and 2.3.3, and “android:rotation” wasn’t legal.

It worked in 3.0 on the emulator, but it was odd. I also added paddingTop=”90dp” to it (to get it away from another component in the test app I tried it in), and it not only moved down the screen, but also to the right (away from the top of the text, since it’s rotated 270 degrees). I don’t have an actual Honeycomb device to test on, but it looks like rotation and padding/margins might not play well together.

There is also an android.view.View#setRotation(double) method that has been added in API 11 which tweaks this property from code. And in addition to rotation, there is rotationX, rotationY, pivotX, pivotY, scaleX, scaleY, and translationX, translationY. I haven’t played with any of them yet.

There is a list of all the changes in API 11.

But I suspect you wanted something that is not only limited to Honeycomb. As far as I know, there isn’t.

Leave a Comment