0

I am trying to create an animation when the user press "back" on his android device. I would like to come back to the previous fragment and close the actual fragment by an animation from up to bottom to close the fragment.

Here is the code when i launch the fragment :

FragmentTransaction fragmentTransaction = getActivity().getFragmentManager().beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_right, R.animator.up_from_bottom);
fragmentTransaction.replace(R.id.content_frame, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();

And here is the code of R.animator.up_from_bottom.xml :

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="@android:anim/decelerate_interpolator">
    <translate
        android:fromXDelta="0%" android:toXDelta="0%"
        android:fromYDelta="100%" android:toYDelta="0%"
        android:duration="400" />
</set>

And here is the exception :

03-19 22:20:38.498: E/InputEventSender(15279): Exception dispatching finished signal.
03-19 22:20:38.498: E/MessageQueue-JNI(15279): Exception in MessageQueue callback: handleReceiveCallback
03-19 22:20:38.498: E/MessageQueue-JNI(15279): java.lang.RuntimeException: Unknown animator name: translate
03-19 22:20:38.498: E/MessageQueue-JNI(15279):  at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:129)
03-19 22:20:38.498: E/MessageQueue-JNI(15279):  at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:126)
03-19 22:20:38.498: E/MessageQueue-JNI(15279):  at android.animation.AnimatorInflater.createAnimatorFromXml(AnimatorInflater.java:93)
03-19 22:20:38.498: E/MessageQueue-JNI(15279):  at android.animation.AnimatorInflater.loadAnimator(AnimatorInflater.java:72)
03-19 22:20:38.498: E/MessageQueue-JNI(15279):  at android.app.FragmentManagerImpl.loadAnimator(FragmentManager.java:743)
03-19 22:20:38.498: E/MessageQueue-JNI(15279):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:958)
03-19 22:20:38.498: E/MessageQueue-JNI(15279):  at android.app.FragmentManagerImpl.removeFragment(FragmentManager.java:1167)
03-19 22:20:38.498: E/MessageQueue-JNI(15279):  at android.app.BackStackRecord.popFromBackStack(BackStackRecord.java:717)
03-19 22:20:38.498: E/MessageQueue-JNI(15279):  at android.app.FragmentManagerImpl.popBackStackState(FragmentManager.java:1496)
03-19 22:20:38.498: E/MessageQueue-JNI(15279):  at android.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:495)
03-19 22:20:38.498: E/MessageQueue-JNI(15279):  at android.app.Activity.onBackPressed(Activity.java:2215)
03-19 22:20:38.498: E/MessageQueue-JNI(15279):  at android.app.Activity.onKeyUp(Activity.java:2193)
03-19 22:20:38.498: E/MessageQueue-JNI(15279):  at android.view.KeyEvent.dispatch(KeyEvent.java:2664)
03-19 22:20:38.498: E/MessageQueue-JNI(15279):  at android.app.Activity.dispatchKeyEvent(Activity.java:2423)
1
  • The problem seems to be the previous attribute: change the android:shareInterpolator to android:interpolator Commented Mar 19, 2014 at 21:36

1 Answer 1

1

when using setCustomAnimation using standard Fragments (as opposed to support library ones) you need to use R.animator instead of R.anim

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.