使用 XML Android 的侧视图 [英] Sideways View with XML Android
问题描述
有没有办法使用 XML 布局文件来显示一个视图,例如横向显示一个 TextView?我知道您可以使用 Activity 中的代码来旋转视图,但有没有办法仅通过布局来实现?
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?
推荐答案
有,但在 API 11 (Android 3.0) 中是新的:
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" />
我在 2.2、2.3.1 和 2.3.3 中尝试过这个,android:rotation"是不合法的.
I tried this in 2.2, 2.3.1, and 2.3.3, and "android:rotation" wasn't legal.
它在模拟器上的 3.0 中工作,但很奇怪.我还向它添加了 paddingTop="90dp" (以使其远离我尝试过的测试应用程序中的另一个组件),它不仅将 向下 移动到屏幕上,而且还移动到 right(远离文本顶部,因为它旋转了 270 度).我没有要测试的实际 Honeycomb 设备,但看起来旋转和填充/边距可能无法很好地配合使用.
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.
API 11 中还添加了一个 android.view.View#setRotation(double)
方法,该方法可以从代码中调整此属性.而且除了旋转之外,还有rotationX,rotationY,pivotX,pivotY,scaleX,scaleY,和translationX,translationY.我还没有和他们一起玩过.
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.
API 11 中的所有更改有一个列表.
但我怀疑你想要的东西不仅限于 Honeycomb.据我所知,没有.
But I suspect you wanted something that is not only limited to Honeycomb. As far as I know, there isn't.
这篇关于使用 XML Android 的侧视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!