FHan
FHan

Reputation: 528

Fragment transaction custom animation - Android

I am trying to do: ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);

But I am getting an exception with Unknown animation name: objectAnimator - see details below:

04-08 10:45:41.637: ERROR/AndroidRuntime(1222): FATAL EXCEPTION: main
04-08 10:45:41.637: ERROR/AndroidRuntime(1222): java.lang.RuntimeException: Unknown animation name: objectAnimator
04-08 10:45:41.637: ERROR/AndroidRuntime(1222):     at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:124)
04-08 10:45:41.637: ERROR/AndroidRuntime(1222):     at android.view.animation.AnimationUtils.createAnimationFromXml(AnimationUtils.java:91)
04-08 10:45:41.637: ERROR/AndroidRuntime(1222):     at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:72)

Why is there an error? I am not sure how to solve it. Please Help. Thanks.

FYI: My min sdk is 7, but I am build for sdk 11 with compatibility library.

Upvotes: 7

Views: 10097

Answers (3)

Freddy Perez
Freddy Perez

Reputation: 1

When your app is over level 11 API.

Change this on imports

  • import android.support.v4.app.Fragment;

with this

  • import android.app.Fragment;

Ensure your app not contains support.v4 import on your imports, otherwise, will have troubles with compilation.

Upvotes: 0

mark.kedzierski
mark.kedzierski

Reputation: 663

I forked the support library to add support for using NineOldAndroids animators in custom fragment transitions. Note that they only work with CustomTransition and not via theme settings. Object animators must be used as View animations will no longer work. android_frameworks_support

Upvotes: 4

mgv
mgv

Reputation: 8484

You have to target 3.0 (API level 11) to use the new object animator. If you are building for lower versions you must use the older anim transitions (android.R.anim).

However, I think that fragment animations in the compat library are broken as stated by Dianne Hackborn in this post.

Upvotes: 9

Related Questions