1

For animation between fragment I'm using the folder anim with the translate tag like this, I got 4 files : slide in from left

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

slide out to left

<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="230" />
</set>

slide in from right

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

slide out to right

<?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="230" />
</set>

This works well between activity, the previous activity translate to the left and the new one appears from the right.

But I can't get the same animation when I call a fragment from an activity. I'm not using the support fragment so I need to use animation with object animator like this :

<objectAnimator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="400"
    android:propertyName="x"
    android:valueFrom="2000"
    android:valueTo="0"
    android:valueType="floatType" />

I got 4 files again for the animation and I'm using it like this :

  transaction.setCustomAnimations(R.animator.slide_in_from_left, R.animator.slide_out_to_left, R.animator.slide_in_from_right, R.animator.slide_out_to_right);

But with this animation the fragment come from the right and come above the activity I would like that the activity translate to the left I try to animate the activity just before call the fragment but this is not working :

findViewById(R.id.main_view).startAnimation( AnimationUtils.loadAnimation(MatchActivity.this, R.anim.slide_out_to_left));

How can I translate the activity when I'm calling the new fragment I want to have the same transition animation between all my view

Vodet
  • 1,491
  • 1
  • 18
  • 36
  • There is a certain place you should perform `setCustomAnimations()`. If you set that line after `add()` or `replace()`, those animations won't be respected. – azizbekian Feb 20 '17 at 16:58
  • Possible dublicate of http://stackoverflow.com/a/11108301/1083957 – azizbekian Feb 20 '17 at 16:58
  • My fragment animations works fine I just want to know how can I get the same animation with translate when I use object animators. Because actually when I call the fragment animation the fragment come above the activity and I want that the previous activity slide on the left – Vodet Feb 21 '17 at 10:23

1 Answers1

0

You need to call your fragment like this getSupportFragmentManagr().beginTransaction().setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_left, R.anim.exit_to_right).replace(R.id.frame, new Settings_Fragment(), "YOUR_TARGET_FRAGMENT_TAG").addToBackStack("4").commit();

Harsh Kapoor
  • 214
  • 1
  • 5