使用XML的Andr​​oid侧身查看XML、Andr、oid

2023-09-13 01:25:01 作者:EXO°青春无悔

有没有办法来显示视图,比如一个TextView横盘使用XML布局文件?我知道你可以用code在活动旋转视图,但有没有办法只是为了与布局办呢?

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(安卓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和和机器人:旋转是不合法

它工作在3.0的模拟器,但很奇怪。我还添加了paddingTop =90dp它(得到它远离测试程序另一部分我想它),它不仅是移动的下的屏幕,而且对右键的(远离文本的顶部,因为它旋转270度)。我没有一个实际的蜂窝设备进行测试,但它看起来像旋转和填充/利润率可能没有发挥得很好。

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调整从code这个属性被添加了一个 android.view.View#setRotation(双)方法。而且除了旋转,还有的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 的所有更改。

但我怀疑你想要的东西,不仅限于蜂窝。据我所知,没有。

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