gpt4 book ai didi

java - Android:如何旋转LinearLayout

转载 作者:搜寻专家 更新时间:2023-10-30 19:55:05 25 4
gpt4 key购买 nike

<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>

现在我想将“线性”布局旋转 90 度。 * 而且我不想使用动画*,还有其他方法可以实现吗?请帮助我。提前致谢!

最佳答案

因为你不需要动画,从 API 11 或更高版本,你可以使用

android:rotation = "90"

在 XML 本身中旋转。如果你想用代码来做,比如在点击按钮之后,那么你也可以使用它的 java equalant

 yourLayout  = (LinearLayout) findViewById(R.id.your_id);
yourLayout.setRotation(90.0f);

但不是在 API 11 之前。参见 documentation .

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.

编辑:看到评论后

yeah,I know this method in API level 11. But what about lower api level?

我认为您必须自己旋转 View 。我相信 lchorus 和皮特在 this 中的回答线程确实有效。对于 Pete 的回答,他使用的是动画,但您可以将动画持续时间设置为 0 以在没有任何可见动画的情况下执行此操作。据我所知,没有其他直接的方法..

关于java - Android:如何旋转LinearLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13698733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com