I\'m using the v4 android compatibility library to develop a tablet UI using fragments specifically for Android 2.2 devices and up.
Everything is working as it shoul
to perform top_to_bottom animation for fragment,
follow same to do top to bottom
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.top_to_bottom_fragment,
android.R.animator.fade_out); ft.replace(R.id.simple_fragment,
fragment);
ft.commit();
top_to_bottom_fragment.xml
<objectAnimator android:duration="400" android:valueFrom="-800"
android:valueTo="0" android:propertyName="y"
android:valueType="floatType"
xmlns:android="http://schemas.android.com/apk/res/android" />
where valueFrom="-800"
indicate bottom of your fragment layout.
I've added NineOldAndroids support to the Google Support library. See http://www.github.com/kedzie/Support_v4_NineOldAndroids for details. It allows using Property Animations for Fragment Transitions, PageTransformers, and some other stuff.
Try getting the most recent ACL again, they have fixed it: http://code.google.com/p/android/issues/detail?id=15623#c19
Also I noticed that for setCustomAnimations, it needs to be set before transaction calls like replace in order to take effect.
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.in_from_left, R.anim.out_to_right, R.anim.in_from_right, R.anim.out_to_left);
ft.replace(android.R.id.content, newFrag);
ft.addToBackStack(null);
ft.commit();
Hope this helps someone. The API docs say use objectAnimator for fragment animations, but even with latest compatibility package objectAnimator in xml wasn't accepted by compiler.
This works for me:
For Android 3.0 or higher: declare xml objectAnimator in res/animator folder.
With Compatibility package for less than 3.0: declare xml animation in res/anim folder.
I finally got this to work after much trial and error.
First and foremost, get the lastest ACL, it did fix custom animations, and while this was not my exact problem, once those worked I ended up using them instead of standard transitions.
Right now I am using:
ft.setCustomAnimations(android.R.anim.fade_in,android.R.anim.fade_out,android.R.anim.fade_in,android.R.anim.fade_out);
The key to making it work on both Android 2.1, 2.2 and 2.3, as well as Android 3.0+ was to do the following:
android:hardwareAccelerated="true"
inside your application tag.Fragment animations now work on all devices. If you do not set the extra info in the application tag, the animation will occur, but in a very very choppy way, making it seem as though it did not happen at all.
Hope this helps someone in the future!
As a note, there are some API checking tools so you are sure you are not using any APIs that aren't available to you. I prefer to work on 2.1 so the IDE doesn't show anything I can't use, once I have stable code I jump back to compiling on 3.0
You must call setCustomAnimations
before you add the fragment. This allows adding multiple fragments with different animations.