Android 使用按钮旋转相对布局-触摸事件区域不';t旋转

Android 使用按钮旋转相对布局-触摸事件区域不';t旋转,android,android-layout,android-animation,Android,Android Layout,Android Animation,我想像这样旋转一个RelativeLayout: 由此: 为此: 到目前为止,我已经尝试过: <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:toDegrees="90" android:fromDegrees="0"

我想像这样旋转一个
RelativeLayout

由此:

为此:

到目前为止,我已经尝试过:

<?xml version="1.0" encoding="utf-8"?>
    <rotate xmlns:android="http://schemas.android.com/apk/res/android"   
            android:toDegrees="90"
            android:fromDegrees="0"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="500"
            android:fillAfter="true"
            android:interpolator="@android:anim/linear_interpolator">
    </rotate>
这是真正的旋转我的按钮布局,但按钮触摸区不旋转。 我的意思是按钮视图看起来像是旋转了90度,但触摸区域保持不变

还有建议? 我的方式(不带
layoutaimationcontroller
)可以吗


提前10倍

这里您正在为视图的表示设置动画,因此按钮和视图实际上处于完全相同的位置。
要移动视图,请使用
ViewPropertyAnimator

layout.animate().rotation(90).start();
和布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:id="@+id/main"
    android:layout_height="match_parent"
    android:background="#ffcc88"
    tools:context=".TestRotateActivity" >

    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Test"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        />

    <Button 
        android:id="@+id/rotate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Rotate"
        android:layout_centerInParent="true"
        />

</RelativeLayout>

为了澄清上述答案,android中有两种动画,视图动画和属性动画,第一种-在不更改视图本身的情况下为视图设置动画,这意味着在视图结束后,必须将视图设置为所需的方式。 后者-在设置动画时更改视图属性本身(宽度、高度、X、Y等)

在你的情况下,后者是正确的选择


此外,属性动画具有更好的性能(它使用vsync),因此如果您的应用程序支持ics及以上版本,并且您可以使用它们,那么它将始终是更好的选择

因为您已经设置了按钮布局的动画。了解您想要旋转的完整区域,或者在创建上述设计的位置显示xml 10X!但你的答案不是动画,而是简单的旋转。我需要与持续时间轮换。你可以添加一个例子链接吗?
RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.main);
int w = mainLayout.getWidth();
int h = mainLayout.getHeight();

mainLayout.setRotation(270.0f);
mainLayout.setTranslationX((w - h) / 2);
mainLayout.setTranslationY((h - w) / 2);

ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) mainLayout.getLayoutParams();
lp.height = w;
lp.width = h;
mainLayout.requestLayout();
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:id="@+id/main"
    android:layout_height="match_parent"
    android:background="#ffcc88"
    tools:context=".TestRotateActivity" >

    <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Test"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        />

    <Button 
        android:id="@+id/rotate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Rotate"
        android:layout_centerInParent="true"
        />

</RelativeLayout>