Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: What's wrong with my fragment transition animation?

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!

like image 307
Hao Zhe XU Avatar asked May 11 '11 04:05

Hao Zhe XU


People also ask

How to animate Fragment transition in android?

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.

What is transition animation in Android?

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.

What are fragments in Android Studio?

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.


2 Answers

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

like image 98
strem Avatar answered Oct 12 '22 21:10

strem


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.

like image 36
FHan Avatar answered Oct 12 '22 23:10

FHan