Android ViewAnimator使用旋转动画在视图之间转换

Android ViewAnimator使用旋转动画在视图之间转换,android,android-layout,view,android-animation,Android,Android Layout,View,Android Animation,我想使用ViewAnimator从一个视图转换到另一个视图(在我的测试应用程序中,视图是文本视图)。下面列出了我的两个动画。我所看到的行为都是在我触发Animator时立即开始动画,而不是让无生命运行,并且在完成后让OutAnimation运行。我所看到的看起来像一个风车——向外旋转的视图与向内旋转的视图垂直。我想看到视图从正常的水平位置(0度)旋转到垂直位置(90度);然后我想看到视图从垂直(-90度)旋转到水平(0度) @anim/rotate_out.xml <?xml versio

我想使用ViewAnimator从一个视图转换到另一个视图(在我的测试应用程序中,视图是文本视图)。下面列出了我的两个动画。我所看到的行为都是在我触发Animator时立即开始动画,而不是让无生命运行,并且在完成后让OutAnimation运行。我所看到的看起来像一个风车——向外旋转的视图与向内旋转的视图垂直。我想看到视图从正常的水平位置(0度)旋转到垂直位置(90度);然后我想看到视图从垂直(-90度)旋转到水平(0度)

@anim/rotate_out.xml

<?xml version="1.0" encoding="UTF-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0" android:toDegrees="90" android:pivotX="50%"
    android:pivotY="50%" android:repeatCount="0" android:duration="500"
    android:interpolator="@android:anim/linear_interpolator">
</rotate>

有什么想法吗?

也许@anim/rotate\u outin.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
  <rotate xmlns:android="http://schemas.android.com/apk/res/android"
      android:fromDegrees="0" android:toDegrees="90" android:pivotX="50%"
      android:pivotY="50%" android:repeatCount="0" android:duration="500"
      android:interpolator="@android:anim/linear_interpolator">
  </rotate>
  <rotate xmlns:android="http://schemas.android.com/apk/res/android"
      android:fromDegrees="0" android:toDegrees="90" android:pivotX="50%"
      android:pivotY="50%" android:repeatCount="0" android:duration="500"
      android:interpolator="@android:anim/linear_interpolator">
  </rotate>
</set>

也许吧@anim/rotate\u outin.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
  <rotate xmlns:android="http://schemas.android.com/apk/res/android"
      android:fromDegrees="0" android:toDegrees="90" android:pivotX="50%"
      android:pivotY="50%" android:repeatCount="0" android:duration="500"
      android:interpolator="@android:anim/linear_interpolator">
  </rotate>
  <rotate xmlns:android="http://schemas.android.com/apk/res/android"
      android:fromDegrees="0" android:toDegrees="90" android:pivotX="50%"
      android:pivotY="50%" android:repeatCount="0" android:duration="500"
      android:interpolator="@android:anim/linear_interpolator">
  </rotate>
</set>

可以找到
ViewAnimator
的源代码。根据那里的
showOnly()
方法,有意将两个动画并行启动,因此当一个视图“移出”时,另一个视图已经“移入”。
因此,为了实现您的目标,您必须为in动画添加一些延迟,以便在out动画已经完成时开始。您可以为out动画设置例如android:duration=“500”,为in动画设置例如android:startOffset=“500”。只需确保两者的值相同。

可以找到
ViewAnimator
的源代码。根据那里的
showOnly()
方法,有意将两个动画并行启动,因此当一个视图“移出”时,另一个视图已经“移入”。
因此,为了实现您的目标,您必须为in动画添加一些延迟,以便在out动画已经完成时开始。您可以为out动画设置例如android:duration=“500”,为in动画设置例如android:startOffset=“500”。只需确保两者的值相同。

由于现在只有一个动画xml文件,我应该为无生命和OutAnimation设置什么?由于现在只有一个动画xml文件,我应该为无生命和OutAnimation设置什么?
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
  <rotate xmlns:android="http://schemas.android.com/apk/res/android"
      android:fromDegrees="0" android:toDegrees="90" android:pivotX="50%"
      android:pivotY="50%" android:repeatCount="0" android:duration="500"
      android:interpolator="@android:anim/linear_interpolator">
  </rotate>
  <rotate xmlns:android="http://schemas.android.com/apk/res/android"
      android:fromDegrees="0" android:toDegrees="90" android:pivotX="50%"
      android:pivotY="50%" android:repeatCount="0" android:duration="500"
      android:interpolator="@android:anim/linear_interpolator">
  </rotate>
</set>