How to manage the transaction between fragments
<p>in my activity i have two fragments one on the right and one on the lef .At some point I need to remove one and add another.But when i remove the left the one that isn't removed expands and the second is added on the right instead of the left.I'll show you a screenshot so  you might understand what i mean.How can i prevent the blue fragment from changing place?
I've used <code>rightFrag.setRetainInstance(true);</code>
but it wont work.Thank you for your time.</p>

<p><img src="http://i.stack.imgur.com/oiRro.png" alt="enter image description here"></p>

<pre><code>  public class MainActivity extends SherlockFragmentActivity implements ActionBar.TabListener {

private final Handler handler = new Handler();
private RoundedColourFragment leftFrag1;
private RoundedColourFragment leftFrag2;
private RoundedColourFragment leftFrag3;
private RoundedColourFragment leftFrag4;
private RoundedColourFragment currentFragment =null;
private RightFragment rightFrag;
private boolean useLogo = false;
private boolean showHomeUp = false;
private FragmentTransaction ft;
private static boolean onLoad=true;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final ActionBar ab = getSupportActionBar();

    // set defaults for logo &amp; home up
    ab.setDisplayHomeAsUpEnabled(showHomeUp);
    ab.setDisplayUseLogoEnabled(useLogo);

    // set up tabs nav
    for (int i = 1; i &lt;= 4; i++) {
        ab.addTab(ab.newTab().setTabListener(this).setText("Tab "+ i));
    }


    // set up list nav
    ab.setListNavigationCallbacks(ArrayAdapter
            .createFromResource(this, R.array.sections,
                    R.layout.sherlock_spinner_dropdown_item),
            new OnNavigationListener() {
                public boolean onNavigationItemSelected(int itemPosition,
                        long itemId) {
                    // FIXME add proper implementation
                    rotateLeftFrag();
                    return false;
                }
            });

    // default to tab navigation
    showTabsNav();

    // create a couple of simple fragments as placeholders
    final int MARGIN = 16;
    leftFrag1 = new RoundedColourFragment(getResources().getColor(
            R.color.abs__bright_foreground_holo_dark), 1f, MARGIN, MARGIN / 2, MARGIN, MARGIN,R.layout.tab1);
    leftFrag2 = new RoundedColourFragment(getResources().getColor(
            R.color.abs__bright_foreground_holo_dark), 4f, MARGIN, MARGIN / 2, MARGIN, MARGIN,R.layout.tab2);
    leftFrag3 = new RoundedColourFragment(getResources().getColor(
            R.color.abs__bright_foreground_holo_dark), 1f, MARGIN, MARGIN / 2, MARGIN, MARGIN,R.layout.tab3);
    leftFrag4 = new RoundedColourFragment(getResources().getColor(
            R.color.abs__bright_foreground_holo_dark), 1f, MARGIN, MARGIN / 2, MARGIN, MARGIN,R.layout.tab4);

    rightFrag = new RightFragment(getResources().getColor(
            R.color.honeycombish_blue), 2f, MARGIN / 2, MARGIN, MARGIN,
            MARGIN);

    ft = getSupportFragmentManager().beginTransaction();

    ft.add(R.id.root, leftFrag1);


   ft.add(R.id.root, rightFrag);


    ft.commit();


    onLoad=false;
    currentFragment=leftFrag1;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getSupportMenuInflater().inflate(R.menu.main_menu, menu);

    // set up a listener for the refresh item
    final MenuItem refresh = (MenuItem) menu.findItem(R.id.menu_refresh);
    refresh.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        // on selecting show progress spinner for 1s
        public boolean onMenuItemClick(MenuItem item) {
            // item.setActionView(R.layout.progress_action);
            handler.postDelayed(new Runnable() {
                public void run() {
                    refresh.setActionView(null);
                }
            }, 1000);
            return false;
        }
    });
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // TODO handle clicking the app icon/logo
        return false;
    case R.id.menu_refresh:
        // switch to a progress animation
        item.setActionView(R.layout.indeterminate_progress_action);
        return true;
    case R.id.menu_both:
        // rotation animation of green fragment
        rotateLeftFrag();
        return true;
    case R.id.menu_text:
        // alpha animation of blue fragment
        ObjectAnimator alpha = ObjectAnimator.ofFloat(rightFrag.getView(),
                "alpha", 1f, 0f);
        alpha.setRepeatMode(ObjectAnimator.REVERSE);
        alpha.setRepeatCount(1);
        alpha.setDuration(800);
        alpha.start();
        return true;
    case R.id.menu_logo:
        useLogo = !useLogo;
        item.setChecked(useLogo);
        getSupportActionBar().setDisplayUseLogoEnabled(useLogo);
        return true;
    case R.id.menu_up:
        showHomeUp = !showHomeUp;
        item.setChecked(showHomeUp);
        getSupportActionBar().setDisplayHomeAsUpEnabled(showHomeUp);
        return true;
    case R.id.menu_nav_tabs:
        item.setChecked(true);
        showTabsNav();
        return true;
    case R.id.menu_nav_label:
        item.setChecked(true);
        showStandardNav();
        return true;
    case R.id.menu_nav_drop_down:
        item.setChecked(true);
        showDropDownNav();
        return true;
    case R.id.menu_bak_none:
        item.setChecked(true);
        getSupportActionBar().setBackgroundDrawable(null);
        return true;
    case R.id.menu_bak_gradient:
        item.setChecked(true);
        getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ad_action_bar_gradient_bak));
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

private void rotateLeftFrag() {
    if (currentFragment!= null) {
        ObjectAnimator.ofFloat(currentFragment.getView(), "rotationY",0,360).setDuration(500).start();

    }
}

private void showStandardNav() {
    ActionBar ab = getSupportActionBar();
    if (ab.getNavigationMode() != ActionBar.NAVIGATION_MODE_STANDARD) {
        ab.setDisplayShowTitleEnabled(true);
        ab.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    }
}

private void showDropDownNav() {
    ActionBar ab = getSupportActionBar();
    if (ab.getNavigationMode() != ActionBar.NAVIGATION_MODE_LIST) {
        ab.setDisplayShowTitleEnabled(false);
        ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    }
}

private void showTabsNav() {
    ActionBar ab = getSupportActionBar();
    if (ab.getNavigationMode() != ActionBar.NAVIGATION_MODE_TABS) {
        ab.setDisplayShowTitleEnabled(false);
        ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    }
}

public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
    // FIXME add a proper implementation, for now just rotate the left
    // fragment

    System.out.println(tab.getPosition());

    if(!onLoad){

        ft = getSupportFragmentManager().beginTransaction();
        ft.remove(currentFragment);

        if(tab.getPosition()==0){
            ft.add(R.id.root, leftFrag1);
            currentFragment=leftFrag1;
        }else if(tab.getPosition()==1){
            ft.add(R.id.root, leftFrag2);
            currentFragment=leftFrag2;
        }else if(tab.getPosition()==2){
            ft.add(R.id.root, leftFrag3);
            currentFragment=leftFrag3;
        }else{
            ft.add(R.id.root, leftFrag4);
            currentFragment=leftFrag4;
        }


        ft.commit();
       // rotateLeftFrag();

    }
}

public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
    // FIXME implement this
}

public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
    // FIXME implement this
}

}
</code></pre>

<p>I have two other classes that concern the fragments,if you think i should post them let me know.</p>
