使用XML Android的侧面视图

ram*_*jan 15 android textview

有没有办法使用XML布局文件显示View,例如TextView?我知道你可以使用活动中的代码来旋转视图,但是有没有办法用布局来做呢?

Dav*_*rad 22

有,但它是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" />
Run Code Online (Sandbox Code Playgroud)

我在2.2,2.3.1和2.3.3中试过这个,而" android:rotation "不合法.

它在模拟器上的3.0工作,但它很奇怪.我还为它添加了paddingTop ="90dp"(为了让它远离我试过的测试应用程序中的另一个组件),它不仅向下移动到屏幕上,而且向右移动(远离文本的顶部) ,因为它旋转了270度).我没有一个真正的Honeycomb设备可供测试,但看起来旋转和填充/边距可能无法很好地协同工作.

android.view.View#setRotation(double)API 11中还添加了一种方法,可以从代码中调整此属性.除旋转外,还有rotationX,rotationY,pivotX,pivotY,scaleX,scaleY和translationX,translationY.我还没玩过任何一个.

API 11中包含所有更改的列表.

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