在android.support.v4.Fragment 3D翻转动画动画、support、android、Fragment

由网友(好男人、不止曾小贤。)分享简介:我目前正在阅读本教程:http://developer.android.com/training/animation/cardflip.html在翻转动画片段的。不幸的是,在对象动画仅适用于android.app.Fragment,而不是在支持片段。 我试图重建使用缩放和旋转动画的动画的.xml。但是,现在只是没有执...

我目前正在阅读本教程:

  

http://developer.android.com/training/animation/cardflip.html

在翻转动画片段的。不幸的是,在对象动画仅适用于android.app.Fragment,而不是在支持片段。

我试图重建使用缩放和旋转动画的动画的.xml。 但是,现在只是没有执行的动画,并通过外,其他片段出现,而不是翻转,我在动画.xml文件所设定的时间后,。

难道我只是做一个misstake在实施的.xml动画? 或者是没可能做3D翻转动画没有对象,动画师? 或者是没可能做3D翻转动画的支持 片段?

下面是我的.xml的动画: flip_left_in.xml

 <设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

  <! - 前旋转,立即设置alpha为0  - >
 <阿尔法
    机器人:valueFrom =1.0
    机器人:valueTo =0.0
    机器人:propertyName的=阿尔法
    机器人:时间=0/>

 &所述;! - 旋转。 - >
 <旋转
    机器人:valueFrom = -  180
    机器人:valueTo =0
    机器人:propertyName的=的rotationY
    机器人:插=@机器人:动画/ accelerate_decelerate_interpolator
    机器人:时间=800/>

<! - 中途通过旋转(见startOffset),设置alpha为1  - >
<阿尔法
    机器人:valueFrom =0.0
    机器人:valueTo =1.0
    机器人:startOffset =400
    机器人:时间=1/>
< /集>
 

flip_left_out.xml

 <设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>

   &所述;! - 旋转。 - >
   <旋转
    机器人:时间=800
    机器人:插=@机器人:动画/ accelerate_decelerate_interpolator
    机器人:propertyName的=的rotationY
    机器人:valueFrom =0
    机器人:valueTo =180/>

<! - 中途通过旋转(见startOffset),设置alpha为0  - >
<阿尔法
    机器人:时间=1
    机器人:propertyName的=阿尔法
    机器人:startOffset =400
    机器人:valueFrom =1.0
    机器人:valueTo =0.0/>

 < /集>
 
android.support.v4.app.FragmentManager无法转换为android.app.FragmentManager

flip_right_in.xml

 <设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
<! - 前旋转,立即设置alpha为0  - >
<阿尔法
    机器人:时间=0
    机器人:propertyName的=阿尔法
    机器人:valueFrom =1.0
    机器人:valueTo =0.0/>

&所述;! - 旋转。 - >
<旋转
    机器人:时间=800
    机器人:插=@机器人:动画/ accelerate_decelerate_interpolator
    机器人:propertyName的=的rotationY
    机器人:valueFrom =180
    机器人:valueTo =0/>

<! - 中途通过旋转(见startOffset),设置alpha为1  - >
<阿尔法
    机器人:时间=1
    机器人:propertyName的=阿尔法
    机器人:startOffset =400
    机器人:valueFrom =0.0
    机器人:valueTo =1.0/>

  < /集>
 

flip_right_out.xml

 <设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
&所述;! - 旋转。 - >
<旋转
    机器人:时间=800
    机器人:插=@机器人:动画/ accelerate_decelerate_interpolator
    机器人:propertyName的=的rotationY
    机器人:valueFrom =0
    机器人:valueTo = -  180/>

<! - 中途通过旋转(见startOffset),设置alpha为0  - >
<阿尔法
    机器人:时间=1
    机器人:propertyName的=阿尔法
    机器人:startOffset =400
    机器人:valueFrom =1.0
    机器人:valueTo =0.0/>

 < /集>
 

和这里就是他们执行的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.

阅读全文

相关推荐

最新文章