replace
private void LoandFragment(Fragment fragment){
FragmentManager fm = getSupportFragmentManager()
FragmentTransaction ft = fm.beginTransaction()
ft.replace(R.id.fragment, fragment)
ft.commitAllowingStateLoss()
}
add
private Fragment currentFragment = new Fragment();
private FragmentTransaction transaction(Fragment targetFragment) {
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
if (!targetFragment.isAdded()) {
if (currentFragment != null) {
transaction.hide(currentFragment);
}
transaction.add(R.id.fragment, targetFragment, targetFragment.getClass().getName());
} else {
transaction
.hide(currentFragment)
.show(targetFragment);
}
currentFragment = targetFragment;
return transaction;
}
性能没什么区别~~~