我目前正在阅读本教程:
http://developer.android.com/training/animation/cardflip.html
关于片段的翻转动画。不幸的是,object-animator仅适用于 android.app.Fragment,不支持 Fragment。
我尝试使用缩放和旋转动画重建 .xml 动画。但是现在动画只是没有执行,并且在我在动画 .xml 文件中设置的时间过去之后,另一个 Fragment 出现了,而不是翻转。
- 我只是在实现 .xml 动画时犯了一个错误吗?
- 或者没有对象动画师就无法制作 3D 翻转动画?
- 还是不能用支持 Fragment 做 3D 翻转动画?
这是我的 .xml 动画:flip_left_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Before rotating, immediately set the alpha to 0. -->
<alpha
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:duration="0" />
<!-- Rotate. -->
<rotate
android:valueFrom="-180"
android:valueTo="0"
android:propertyName="rotationY"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="800"/>
<!-- Half-way through the rotation (see startOffset), set the alpha to 1. -->
<alpha
android:valueFrom="0.0"
android:valueTo="1.0"
android:startOffset="400"
android:duration="1" />
</set>
flip_left_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Rotate. -->
<rotate
android:duration="800"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="rotationY"
android:valueFrom="0"
android:valueTo="180" />
<!-- Half-way through the rotation (see startOffset), set the alpha to 0. -->
<alpha
android:duration="1"
android:propertyName="alpha"
android:startOffset="400"
android:valueFrom="1.0"
android:valueTo="0.0" />
</set>
flip_right_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Before rotating, immediately set the alpha to 0. -->
<alpha
android:duration="0"
android:propertyName="alpha"
android:valueFrom="1.0"
android:valueTo="0.0" />
<!-- Rotate. -->
<rotate
android:duration="800"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="rotationY"
android:valueFrom="180"
android:valueTo="0" />
<!-- Half-way through the rotation (see startOffset), set the alpha to 1. -->
<alpha
android:duration="1"
android:propertyName="alpha"
android:startOffset="400"
android:valueFrom="0.0"
android:valueTo="1.0" />
</set>
flip_right_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Rotate. -->
<rotate
android:duration="800"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="rotationY"
android:valueFrom="0"
android:valueTo="-180" />
<!-- Half-way through the rotation (see startOffset), set the alpha to 0. -->
<alpha
android:duration="1"
android:propertyName="alpha"
android:startOffset="400"
android:valueFrom="1.0"
android:valueTo="0.0" />
</set>
这是执行它们的代码:
FragmentTransaction trans = getActivity().getSupportFragmentManager().beginTransaction();
trans.setCustomAnimations(R.anim.flip_right_in, R.anim.flip_right_out,
R.anim.flip_left_in, R.anim.flip_left_out);
trans.addToBackStack(null);
trans.replace(R.id.content_frame, new MyFragment()).commit();