解决方案 »

  1.   

    public void switchContent(Fragment from, Fragment to) {
            if (mContent != to) {
                mContent = to;
                FragmentTransaction transaction = mFragmentMan.beginTransaction().setCustomAnimations(
                        android.R.anim.fade_in, R.anim.slide_out);
                if (!to.isAdded()) {    // 先判断是否被add过
                    transaction.hide(from).add(R.id.content_frame, to).commit(); // 隐藏当前的fragment,add下一个到Activity中
                } else {
                    transaction.hide(from).show(to).commit(); // 隐藏当前的fragment,显示下一个
                }
            }
        }
      

  2.   


    public void switchContent(Fragment from, Fragment to) {
            if (mContent != to) {
                mContent = to;
                FragmentTransaction transaction = mFragmentMan.beginTransaction().setCustomAnimations(
                        android.R.anim.fade_in, R.anim.slide_out);
                if (!to.isAdded()) {    // 先判断是否被add过
                    transaction.hide(from).add(R.id.content_frame, to).commit(); // 隐藏当前的fragment,add下一个到Activity中
                } else {
                    transaction.hide(from).show(to).commit(); // 隐藏当前的fragment,显示下一个
                }
            }
        }
    这个确实是可以的。