swap fragment in an activity via animation

I want to swap two fragment in an activity via animation.Suppose PageA is for fragement A and left side on the screen and PageB is for fragment B i.e. on the right side of the screen. Now i want that when i click a button on pageA then PageA will move to the right side of the screen with some transition animation.

I tried the below code to replace the position

  • Line Break in XML formatting?
  • Activity's slide animation with overridePendingTransition having an strange effect
  • Error while waiting for device: Time out after 300seconds waiting for emulator to come online
  • Android M requesting permissions with permission_groups
  • Using LibPhoneNumber google lib in Android
  • How to create Vertical Carousel in android?
  • FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.container, new FragB());

    Looking for some clue.

    Thanks in advance.

    Related posts:

    Add object to ArrayList at specified index
    GLSurfaceView inside fragment not rendering when restarted
    Losing data when rotate screen
    SQLite database for Android app with potential multiple users
    To force cancel AsyncTask shouldn't the flag periodically checked in doInBackground be vola...
    UserNotAuthenticatedException during FingerprintManager.authenticate()
  • How to add new Column to Android SQLite Database?
  • WARNING : No target specified, deploying to emulator
  • Gradle version 1.8 is required. Current version is 1.9-rc-3 - Android Studio
  • Real-time audio processing in Android
  • Send email via gmail
  • How to query value of column that is set as pointer to other table in Parse
  • One Solution collect form web for “swap fragment in an activity via animation”

    Old questiion and you probably already figured it out, but for future reference:

    here’s what you use to set a custom animation when you replace a fragment via code:

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
    ft.replace(R.id.fragment_container, newFragment, "fragment");
    // Start the animated transition.

    Here is an example of the slide_in_left animation:

    <?xml version="1.0" encoding="utf-8"?>
      <translate xmlns:android="http://schemas.android.com/apk/res/android"

    Note that this is the animation if you are using the compatibility library. Instead if you are using and SDK with native support for the FragmentManager then your animation will look like this:

    <?xml version="1.0" encoding="utf-8"?>
      <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"

    This is because the compatibility library does not support the new objectAnimator type and instead only implement the old animation framework.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.