3

Running a simple slide to the left animation for both entering and existing fragment produces the effect of the entering fragment slightly overlapping with the exit fragment. This leads me to think that both transition are not executed at the same time. Any clue or confirmation of this behavior?

The desired effect is to slide the fragments to the left at the same time, without overlap.

The code:

Fragment current = ...;
Fragment fragment = ...;
Transition slideIn = TransitionInflater.from(this)
     .inflateTransition(R.transition.fragment_indicator_enter)
     .setDuration(300)
     .setInterpolator(new LinearInterpolator());
fragment.setEnterTransition(slideIn);

currentFragment.setExitTransition(TransitionInflater.from(this)
     .inflateTransition(R.transition.fragment_indicator_exit)
     .setDuration(300)
     .setInterpolator(new LinearInterpolator()));

getSupportFragmentManager()
     .beginTransaction()
     .replace(R.id.fragment_container, fragment)
     .addToBackStack(null)
     .commit();

The only workaround by know it has been to add a setStartDelay(30) for the entering transition. But weird thing, I have different transitions for different fragments and the startDelay has to be different to produce the effect of both fragment sliding to the left at the same time.

4

2 回答 2

2

The effect is an expected behavior of the transition, as all the views in the layout are moved at a different time to avoid moving everything as a block a create some natural sense of motion. I intentionally want this block effect, so it's solved by adding a target for the transition, where this target is the FrameLayout containing the views of the fragment.

fragment.setEnterTransition(new Slide(Gravity.RIGHT)
                    .addTarget(R.id.whole_content));
于 2016-05-09T13:34:50.603 回答
0

Did you try placing the animations directly in the transaction call?

getSupportFragmentManager()
 .setCustomAnimations(R.transition.fragment_indicator_enter, R.transition.fragment_indicator_exit)
 .beginTransaction()
 .replace(R.id.fragment_container, fragment)
 .addToBackStack(null)
 .commit();
于 2016-05-09T10:11:03.137 回答