Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

textview - Sideways View with XML Android

Is there a way to display a View, such as a TextView sideways using the XML layout file? I know you can rotate the view using code in an activity, but is there a way just to do it with layout?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...