ViewAnimator using rotate anim to transition between views
I want to use a ViewAnimator to transition from one view to another (in my test app, views are TextViews). My two animations are listed below. The behavior I am seeing is both animations starting as soon as I trigger the aniimator as opposed to having the InAnimation run and once it's done having the OutAnimation run. What I'm seeing looks like a pinwheel - the view rotating out is perpendicular to the view rotating in. I want to see the view rotating out to go from it's normal horizontal position (0 degrees) to vertical (90 degrees); then I want to see the view rotating in to go from vertical (-90 degrees) to horizontal (0 degrees).
@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>
and in the main activity onCreate...
va = (ViewAnimator) findViewById(R.id.ViewFlipper01);
va开发者_StackOverflow社区.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate_in));
va.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate_out));
any ideas?
maybe ? @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>
The source code of ViewAnimator
can be found here. According to the showOnly()
method there, it is intentional that both animations are started in parallel, so while one view is "moved out", the other one is already "moved in".
So to achieve your goal, you have to add some delay to the in-animation so it starts when the out-animation is already finished. You could set e.g. android:duration="500" for the out-animation and android:startOffset="500" to the in-animation. Just make sure its the same values for both.
精彩评论