0

I want animation between fragments. The second fragment should slide out from bottom right and the first(current fragment should stay as it is) this should happen on click of a FAB Button.

What I have tried.

ft.setCustomAnimations(R.anim.slide_in_from_bottom_right,R.anim.stay);

                ft.replace(R.id.sample_content_fragment, fragment, "XYZ");
                ft.addToBackStack("XYZ");
                Bundle bundle = new Bundle();

                fragment.setArguments(bundle);
                ft.commit();

slide_in_from_bottom_right.xml:-

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromYDelta="100%p" android:fromXDelta="100%p" android:toYDelta="0%p"
        android:duration="600"
        android:fillAfter="true"
        android:interpolator="@android:anim/linear_interpolator"
        />
</set>

stay.xml:-

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:duration="600"/>
</set>

The problem is that I am not able to see the actual sliding in. What have I missed here?

Vishal Senjaliya
  • 454
  • 6
  • 21
Sreekanth Karumanaghat
  • 3,383
  • 6
  • 44
  • 72

1 Answers1

0

If you want to keep the first fragment as it is then you don't need to define animation resource for the first fragment.

ft.setCustomAnimations(R.anim.slide_in_from_bottom_right,0);

I just updated your slide_in_from_bottom_right.xml to translate the view perfectly from 100% x and y to 0% x and y.

slide_in_from_bottom_right.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate 
  android:fromYDelta="100%p" 
  android:fromXDelta="100%p" 
  android:toYDelta="0%p"
  android:toXDelta="0%p"
  android:duration="600"
  android:fillAfter="true"
  android:interpolator="@android:anim/linear_interpolator"
/>

You can also set the pop animation for the second fragment when you back from the second fragment to the first fragment.

ft.setCustomAnimations(R.anim.slide_in_from_bottom_right,0,0,R.anim.pop_slide_in_from_top_left.xml);

pop_slide_in_from_top_left.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="600">

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="600"
    android:fromXDelta="0%p"
    android:fromYDelta="0%p"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:toXDelta="100%p"
    android:toYDelta="100%p" />
</set>
Aman Jain
  • 2,975
  • 1
  • 20
  • 35