java Android:如何旋转 LinearLayout
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13698733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android:How to rotate LinearLayout
提问by Rocky
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg2x" >
<LinearLayout
android:id="@+id/linear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:layout_alignParentTop="true"
android:background="#FF00FF00"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FF000000"
android:textSize="70dp"
android:text="test linearlayout"
/>
</LinearLayout>
Now I wanna Rotatethe "linear" layout by 90 degrees. * And I dont wanna use Animation*, is there any other way to achive this? Please help me.Thanks in advance!!
现在我想将“线性”布局旋转90 度。* 而且我不想使用 Animation*,还有其他方法可以实现吗?请帮助我。提前致谢!!
回答by Krishnabhadra
Since you don't need animation, from API 11 or above, you can use
由于您不需要动画,从 API 11 或更高版本开始,您可以使用
android:rotation = "90"
to rotate in XML itself. If you want to do it in code, say after a button click, then you can use its java equalant too
在 XML 本身中旋转。如果你想在代码中做到这一点,比如在单击按钮之后,那么你也可以使用它的 java equalant
yourLayout = (LinearLayout) findViewById(R.id.your_id);
yourLayout.setRotation(90.0f);
But not before API 11. See documentation.
但不是在 API 11 之前。请参阅文档。
android:rotation
rotation of the view, in degrees.
Must be a floating point value, such as "1.2".
This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
This corresponds to the global attribute resource symbol rotation.
机器人:旋转
视图的旋转,以度为单位。
必须是浮点值,例如“1.2”。
这也可能是对包含此类型值的资源(以“@[package:]type:name”形式)或主题属性(以“?[package:][type:]name”形式)的引用.
这对应于全局属性资源符号轮换。
EDIT: After seeing comment
编辑:看到评论后
yeah,I know this method in API level 11. But what about lower api level?
是的,我在 API 级别 11 中知道这种方法。但是较低的 api 级别呢?
I think you can have to rotate the view yourselves. And I believe the lchorus and Pete's answer in thisthread does work. For Pete's answer he is using animation, but you can set animation duration of 0 to do it without any visible animation. There is no other straight forward way as far as I know..
我认为您必须自己旋转视图。我相信 lchorus 和 Pete 在这个线程中的回答确实有效。对于皮特的回答,他正在使用动画,但您可以将动画持续时间设置为 0 来实现它而没有任何可见的动画。据我所知,没有其他直接的方法。
回答by Dmitry Ryadnenko
Using this library you can rotate whole view hierarchy https://github.com/rongi/rotate-layout
使用此库,您可以旋转整个视图层次结构https://github.com/rongi/rotate-layout
Like this
像这样