Android lollipop - setentertransition () for a fragment that does not work properly when exiting

When replacing a fragment, I use the slide animation available for the lollipop version for Android. It works as expected for this particular replacement, but when you press the back button, the current fragment is pushed out first and then the input animation is reversed (slide).

private void replaceContentFrameByFragment(Fragment replaceBy, String replaceByFragmentTag) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Slide slide = new Slide(Gravity.BOTTOM); slide.setDuration(1000); replaceBy.setEnterTransition(slide); } FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.content_frame, replaceBy, replaceByFragmentTag); fragmentTransaction.addToBackStack(null); fragmentTransaction.commitAllowingStateLoss(); } 

So, how to make a fragment pop up only after the slide animation is completed? I noticed that the activity has a finishAfterTransition () method. Is there something similar for frgament?

+5
source share
2 answers

I had the same problem with about the same model and she was able to get around it by posting a switch to fragments:

 new Handler().post(new Runnable() { @Override public void run() { page.setEnterTransition(new Slide()); getFragmentManager() .beginTransaction() .replace(R.id.root_layout, page, "current") .commit(); } }); 

Not sure why this solves the problem (or if this is the absolutely correct solution), but it worked for me.

0
source

I had the same problem: onReturn from Fragment B -> A, Fragment B seems to be doing an additional slide transition. To get around this, I turned on the transition for setReturnTransition() a shorter time than a slide that looks good (since it dissolves in the previous snippet). Code for this:

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Slide slideRight = new Slide(Gravity.RIGHT); slideRight.setDuration(200); fragment.setEnterTransition(slideRight); Fade fade = new Fade(); fade.setDuration(100); fragment.setReturnTransition(fade); } 
0
source

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


All Articles