我想使用ViewAnimator从一个视图转换到另一个视图(在我的测试应用程序中,视图是TextViews)。下面列出了我的两个动画。我看到的行为是,当我触发模拟器时,动画就会立即开始,而不是让InAnimation运行,而且一旦它完成了,就会让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_in.xml
<?xml version="1.0" encoding="UTF-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="-90" android:toDegrees="0" android:pivotX="50%"
android:pivotY="50%" android:repeatCount="0" android:duration="500"
android:interpolator="@android:anim/linear_interpolator">
</rotate>在主要的活动onCreate中...
va = (ViewAnimator) findViewById(R.id.ViewFlipper01);
va.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate_in));
va.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate_out));有什么想法吗?
发布于 2011-10-07 00:35:16
也许?@anim/rotate_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>发布于 2011-10-14 16:34:35
可以在here中找到ViewAnimator的源代码。根据那里的showOnly()方法,有意将两个动画并行启动,因此当一个视图“移出”时,另一个视图已经“移入”。因此,为了实现您的目标,您必须在动画中添加一些延迟,以便在输出动画已经完成时开始。您可以将输出动画设置为android:duration="500“,将android:startOffset="500”设置为动画内动画。只需确保两者的值相同即可。
https://stackoverflow.com/questions/7677422
复制相似问题