1

When transitioning from one fragment HelloAfragment to HelloBfragment using below code, how to add a delay when transitioning from HelloAfragment to HelloBfragment

   TAG = HelloFrament.class.getSimpleName();
   fragmentManager.beginTransaction()
           .setCustomAnimations(R.anim.slide_in_left,R.anim.slide_out_right)
            .replace(HelloAfragment.getId(), HelloBfragment, TAG)
            .addToBackStack(TAG)
            .commit();
livemaker
  • 464
  • 1
  • 9
  • 19
Vijay
  • 191
  • 1
  • 1
  • 9

3 Answers3

0

Try following code

            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
            fragmentManager.addOnBackStackChangedListener(this);
            fragmentTransaction.replace(R.id.frame, firstFragment, "h");
            fragmentTransaction.addToBackStack("h");
            fragmentTransaction.commit();
Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
  • Use this code for animation given by android studio.. `fragmentTransaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right);` – Gowthaman M Sep 22 '17 at 05:03
0

You simply need a small change, Use below code in slide_in_left

<translate xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/linear_interpolator"
       android:fromXDelta="1000" android:toXDelta="0"
       android:duration="700"/>

and this Code for slide_in_right

<translate xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/accelerate_decelerate_interpolator"
       android:fromXDelta="0" android:toXDelta="-1000"
       android:duration="700"/>
Meet
  • 501
  • 4
  • 16
0

I was unable to achieve transition between two fragment's, so I ended up changing the destination fragment to activity and used the below code for activity

       View imageView = findViewById(R.id.imageView);
    View textView = findViewById(R.id.textView);
    View button = findViewById(R.id.button);

    Intent intent = new Intent(this, EndActivity.class);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        textView.setTransitionName(getString(R.string.activity_text_trans));
        button.setTransitionName(getString(R.string.activity_mixed_trans));

        Pair<View, String> pair1 = Pair.create(imageView, imageView.getTransitionName());
        Pair<View, String> pair2 = Pair.create(textView, textView.getTransitionName());
        Pair<View, String> pair3 = Pair.create(button, button.getTransitionName());
        ActivityOptionsCompat options = ActivityOptionsCompat.
                makeSceneTransitionAnimation(this, pair1, pair2, pair3);
        startActivity(intent, options.toBundle());
    }
    else {
        startActivity(intent);
    }
}
Vijay
  • 191
  • 1
  • 1
  • 9