I just need plain slide in and slide out animation for Fragment transition, below is my code: slide_in_left.xml:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true">
<translate
android:fromXDelta="-100%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="700">
</translate>
</set>
slide_out_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700">
</translate>
</set>
the code I used:
SomeFragment frag = SomeFragment.newInstance(foo);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
ft.replace(R.id.the_fragment, frag);
ft.addToBackStack(null);
ft.commit();
The result looks very stranges, when the transition starts, the current fragment disappears without animation, the entering fragment comes(from left) like a scrolling paper. What's wrong with my animation xml code?
Thanks!
At a high level, here's how to make a fragment transition with shared elements: Assign a unique transition name to each shared element view. Add shared element views and transition names to the FragmentTransaction . Set a shared element transition animation.
Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.
A Fragment is a piece of an activity which enable more modular activity design. It will not be wrong if we say, a fragment is a kind of sub-activity. A fragment has its own layout and its own behaviour with its own life cycle callbacks. You can add or remove fragments in an activity while the activity is running.
getSupportFragmentManager() means you are using the Compatibility Package for Fragments, I guess. I have the same problem, which is no animation happening at all.
See http://groups.google.com/group/android-developers/browse_thread/thread/5ef5ba1be9f40c56/a846578d91a032c0?hide_quotes=yes#msg_8ca017c473818a04
Google has updated the compatibility library and the transitions have been fixed. You guys should update your compatiblity library from the android sdk/avd manager.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With