I have two fragments in an activity. When i go from fragment A to fragment B, custom animation have been added. So that the view of fragment B slides in from the right on entry and then slides back out from right on exit.
But the fragment B can been seen to be entering from behind the view of fragment A. So when Fragment A is replaced by Fragment B, the view of Fragment B animates from right to left but it comes in from behind the view of Fragment A and not in front of Fragment A.
I am able to notice this since half of Fragment A is transparent and Fragment B sliding in can be seen only from that transparent half indicating that it is sliding in from behind Fragment A and not from the front.
Not entirely sure why this is happening. The respective code has been provided below. Could someone please help?
private void navigateToFragment(@NonNull Fragment fragment, boolean addToBackStack, int enterAnim, int exitAnim, int popEnterAnim, int popExitAnim) {
FragmentManager fragmentManager = getSupportFragmentManager();
final FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.setCustomAnimations(enterAnim, exitAnim, popEnterAnim, popExitAnim);
transaction.replace(R.id.member_address_root, fragment, fragment.getClass().getSimpleName());
if (addToBackStack){
transaction.addToBackStack(fragment.getTag());
}
fragmentManager.executePendingTransactions();
transaction.commit();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_member_address);
if (savedInstanceState == null){
if (getIntent() != null){
Fragment fragment = FragmentA.newInstance();
navigateToFragment(fragment, false, R.anim.no_animation, R.anim.no_animation, R.anim.no_animation, R.anim.no_animation);
}
}
}
@Override
public void onFragmentBRequested() {
FragmentB fragment = new FragmentB();
navigateToFragment(fragment, true, R.anim.enter_from_right, R.anim.no_animation, R.anim.no_animation, R.anim.exit_from_right);
}
onFragmentBRequested() is called from FragmentA based on a button click.