在android.support.v4.Fragment 3D翻转动画 [英] 3D Flip Animation on android.support.v4.Fragment
问题描述
我目前正在阅读本教程:
<一个href="http://developer.android.com/training/animation/cardflip.html">http://developer.android.com/training/animation/cardflip.html
在翻转动画片段的。不幸的是,在对象动画仅适用于android.app.Fragment,而不是在支持片段。
我试图重建使用缩放和旋转动画的动画的.xml。 但是,现在只是没有执行的动画,并通过外,其他片段出现,而不是翻转,我在动画.xml文件所设定的时间后,。
- 难道我只是做一个misstake在实施的.xml动画?
- 或者是没可能做3D翻转动画没有对象,动画师?
- 或者是没可能做3D翻转动画的支持 片段?
下面是我的.xml的动画: flip_left_in.xml
&LT;设置的xmlns:机器人=http://schemas.android.com/apk/res/android&GT;
&LT;! - 前旋转,立即设置alpha为0 - &GT;
&LT;阿尔法
机器人:valueFrom =1.0
机器人:valueTo =0.0
机器人:propertyName的=阿尔法
机器人:时间=0/&GT;
&所述;! - 旋转。 - &GT;
&LT;旋转
机器人:valueFrom = - 180
机器人:valueTo =0
机器人:propertyName的=的rotationY
机器人:插=@机器人:动画/ accelerate_decelerate_interpolator
机器人:时间=800/&GT;
&LT;! - 中途通过旋转(见startOffset),设置alpha为1 - &GT;
&LT;阿尔法
机器人:valueFrom =0.0
机器人:valueTo =1.0
机器人:startOffset =400
机器人:时间=1/&GT;
&LT; /集&gt;
flip_left_out.xml
&LT;设置的xmlns:机器人=http://schemas.android.com/apk/res/android&GT;
&所述;! - 旋转。 - &GT;
&LT;旋转
机器人:时间=800
机器人:插=@机器人:动画/ accelerate_decelerate_interpolator
机器人:propertyName的=的rotationY
机器人:valueFrom =0
机器人:valueTo =180/&GT;
&LT;! - 中途通过旋转(见startOffset),设置alpha为0 - &GT;
&LT;阿尔法
机器人:时间=1
机器人:propertyName的=阿尔法
机器人:startOffset =400
机器人:valueFrom =1.0
机器人:valueTo =0.0/&GT;
&LT; /集&gt;
flip_right_in.xml
&LT;设置的xmlns:机器人=http://schemas.android.com/apk/res/android&GT;
&LT;! - 前旋转,立即设置alpha为0 - &GT;
&LT;阿尔法
机器人:时间=0
机器人:propertyName的=阿尔法
机器人:valueFrom =1.0
机器人:valueTo =0.0/&GT;
&所述;! - 旋转。 - &GT;
&LT;旋转
机器人:时间=800
机器人:插=@机器人:动画/ accelerate_decelerate_interpolator
机器人:propertyName的=的rotationY
机器人:valueFrom =180
机器人:valueTo =0/&GT;
&LT;! - 中途通过旋转(见startOffset),设置alpha为1 - &GT;
&LT;阿尔法
机器人:时间=1
机器人:propertyName的=阿尔法
机器人:startOffset =400
机器人:valueFrom =0.0
机器人:valueTo =1.0/&GT;
&LT; /集&gt;
flip_right_out.xml
&LT;设置的xmlns:机器人=http://schemas.android.com/apk/res/android&GT;
&所述;! - 旋转。 - &GT;
&LT;旋转
机器人:时间=800
机器人:插=@机器人:动画/ accelerate_decelerate_interpolator
机器人:propertyName的=的rotationY
机器人:valueFrom =0
机器人:valueTo = - 180/&GT;
&LT;! - 中途通过旋转(见startOffset),设置alpha为0 - &GT;
&LT;阿尔法
机器人:时间=1
机器人:propertyName的=阿尔法
机器人:startOffset =400
机器人:valueFrom =1.0
机器人:valueTo =0.0/&GT;
&LT; /集&gt;
和这里就是他们执行的code:
FragmentTransaction反= 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(空);
trans.replace(R.id.content_frame,新MyFragment())提交()。
您可以使用 NineOldAndroids 。它反向移植的蜂窝(安卓3.0)的动画API的所有返回的途中到Android 1.0。你会得到ObjectAnimator,ValueAnimator和所有其他的好东西。
I am currently reading this tutorial:
http://developer.android.com/training/animation/cardflip.html
on flip Animations of Fragments. Unfortunately, the object-animator is only available for android.app.Fragment, and not the support Fragment.
I tried to reconstruct the .xml animations using scale and rotation animations. But now the animations are just not executed, and after the time that I've set in the animations .xml file passes, the other Fragment appears, instead of flipping.
- Did I simply make a misstake in implementing the .xml animations?
- Or is it not possible to do a 3D flip animation without object-animator?
- Or is it not possible to do a 3D flip animation with the support Fragment?
Here are my .xml animations: 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>
And here is the code where they are executed:
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();
You can use NineOldAndroids. It backports the Honeycomb (Android 3.0) animation API all the way back to Android 1.0. You'll get ObjectAnimator, ValueAnimator and all the other good stuff.
这篇关于在android.support.v4.Fragment 3D翻转动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!