片段v4动画崩溃

时间:2015-04-23 15:41:27

标签: android

我正在使用片段v4,最小API = 14。

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();        
    ft.setCustomAnimations(
             R.anim.fragment_slide_left_enter,
             R.anim.fragment_slide_left_exit,
             R.anim.fragment_slide_right_enter,
             R.anim.fragment_slide_right_exit);
    ft.replace(R.id.content_frame, myLogFragment).commit(); 

但是当我使用动画时,应用程序崩溃了

04-23 16:36:01.718: E/AndroidRuntime(5899): FATAL EXCEPTION: main
04-23 16:36:01.718: E/AndroidRuntime(5899): Process: com.ingenico.rbasimulator, PID: 5899
04-23 16:36:01.718: E/AndroidRuntime(5899): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ingenico.rbasimulator/com.ingenico.rbasimulator.EcrActivity}: java.lang.RuntimeException: Unknown animation name: objectAnimator
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.app.ActivityThread.access$800(ActivityThread.java:151)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.os.Looper.loop(Looper.java:135)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.app.ActivityThread.main(ActivityThread.java:5254)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at java.lang.reflect.Method.invoke(Native Method)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at java.lang.reflect.Method.invoke(Method.java:372)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
04-23 16:36:01.718: E/AndroidRuntime(5899): Caused by: java.lang.RuntimeException: Unknown animation name: objectAnimator
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:126)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:116)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:93)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:74)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.support.v4.app.FragmentManagerImpl.loadAnimation(FragmentManager.java:786)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:963)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1136)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1499)
04-23 16:36:01.718: E/AndroidRuntime(5899):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:548)

我该如何解决?

2 个答案:

答案 0 :(得分:0)

您必须将R.anim个文件转换为R.animation

http://developer.android.com/guide/topics/graphics/prop-animation.html#declaring-xml

  

要区分使用新属性动画API的动画文件和使用旧版视图动画框架的动画文件,从Android 3.1开始,您应该在res / animator /目录中保存属性动画的XML文件(而不是res /阿尼姆/)。使用animator目录名是可选的,但是如果你想使用Eclipse ADT插件(ADT 11.0.0+)中的布局编辑器工具,则必须使用,因为ADT只搜索res / animator /目录中的属性动画资源。

答案 1 :(得分:0)

您正试图从objectAnimator FragmentTransaction申请support library。但支持库只能应用ValuePropertyAlphaTranslation动画... AnimatorSet

<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:fromXDelta="-100%p"
android:interpolator="@android:anim/decelerate_interpolator"
android:toXDelta="0%p"/>

试试这个