replace Content Fragment With Animation - Android User Interface

Android examples for User Interface:Fragment

Description

replace Content Fragment With Animation

Demo Code


//package com.java2s;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

public class Main {
    public static void replaceContentFragmentWithAnim(
            FragmentActivity activity, final int containerId,
            Fragment frgmt, int enterAnimId, int exitAnimId) {
        FragmentManager manager = activity.getSupportFragmentManager();

        FragmentTransaction ft = manager.beginTransaction();
        ft.setCustomAnimations(enterAnimId, exitAnimId);
        manager.popBackStackImmediate(null,
                FragmentManager.POP_BACK_STACK_INCLUSIVE);
        manager.beginTransaction().replace(containerId, frgmt)
                .commitAllowingStateLoss();
    }/*  w ww. j  av  a 2s  . c  o  m*/
}

Related Tutorials