1、方法一:在大神博客里看到的 http://blog.csdn.net/harvic880925/article/details/44948027
这个方法的逻辑是,需要显示哪个就显示哪个,要隐藏哪个就隐藏哪个。
public void switchContent(Fragment from, Fragment to) {
if (!to.isAdded()) { // 先判断是否被add过
transaction.hide(from).add(R.id.content_frame, to).commit();
} else {
transaction.hide(from).show(to).commit();
}
}
我很好奇怎么得到当前显示的Fragment from的,网上很多说用这个方法:
Fragment fromFragment = fragmentManager