I trying to use the new android compatibility package to include fragments into my project. I am trying to include a transition animation when I add a new fragment. The thing is only one of my animation work. The In animation works but the Out animation doesn't work. I read somewhere that it is a bug in the compatibility package. But I also read that the bug was fixed in the 3rd revision of the compatibility package. Can anyone help me with this issue
In Animation
<translate xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/anticipate_interpolator" android:fromXDelta="0" android:toXDelta="0" android:fromYDelta="100%" android:toYDelta="0%" android:duration="1000"/>
Out Animation
<translate xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" android:fromXDelta="0" android:toXDelta="0" android:zAdjustment="top" android:fromYDelta="0%" android:toYDelta="100%" android:duration="1000"/>
This is the code I use to add fragments
newFragment = new HelloWorldFragment(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.setCustomAnimations(R.anim.bottom_top_animation, R.anim.top_bottom_animation); ft.add(R.id.outer_layout, newFragment); ft.addToBackStack(null); ft.commit();
This works in the current version of the library, but it was definitely broken previously. You can use something like this:
final FragmentManager fm = getSupportFragmentManager(); final FragmentTransaction ft = fm.beginTransaction(); ft.setCustomAnimations(R.anim.slide_up, R.anim.slide_down, R.anim.slide_up, R.anim.slide_down) .add(R.id.fragment_container, new SomeFragment(), FRAGMENT_TAG) .addToBackStack(FRAGMENT_TAG) .commit();
where R.anim.slide_up is your in animation and R.anim.slide_down is your out animation. The second pair of params (3 and 4) for setCustomAnimations allow you to specify the pop in/out animations for popping the backstack (e.g., when the user presses back, the fragment will animate away with the animation specified as the fourth param).
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