How to show fragment fragment over output fragment during animation.

The effect I want to achieve is to overlay a new (new) fragment over the output (old) fragment, but when I replace the old fragment with a new fragment, the old one just disappears and the new fragment glides over the container that we see (container).

I don’t want to animate the old fragment, just keeping the old fragment as it is, and while it is visible, slide the new fragment over it.

Below is my code:

// First time adding fragment ie "oldFragemnt" FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.content_frame, oldFragment, "oldFragemnt"); ft.addToBackStack(null); ft.commit(); // while adding "newFragemnt" FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.setCustomAnimations(R.anim.new_slide_in_up,0,0,R.anim.new_slide_out_down); ft.replace(R.id.content_frame, newFragment, "newFragemnt"); ft.addToBackStack(null); ft.commit(); 

Guide me where I'm wrong My old fragment disappears and the new fragment unfolds.

+6
source share
2 answers

The new snippet should have this input animation (which you can already do): enter.xml

 <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <translate android:duration="400" android:fromXDelta="90%" android:fromYDelta="0%" android:toXDelta="0%" android:toYDelta="0%" android:zAdjustment="top" /> 

The old fragment should remain in the same place as hold. hold.xml

 <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <translate android:duration="400" android:zAdjustment="bottom" /> 

0
source

You can try replacing replace () with add () to achieve the desired effect. Hope this helps you.

0
source

Source: https://habr.com/ru/post/980746/


All Articles