Android: fragments overlapping issue

前端 未结 17 1485
闹比i
闹比i 2020-11-27 17:49

I am facing a problem of overlapping fragments when i switch between tabs and attach fragments to a tab view below is my code please help

public class Fragme         


        
17条回答
  •  眼角桃花
    2020-11-27 18:12

    Well Setting up fragment background color is not a solution because fragment will be still in the activity stack which may consume memory.

    Solution would be remove all views from your framelayout before adding any new fragment.

    private void changeFragment(Fragment fr){
        FrameLayout fl = (FrameLayout) findViewById(R.id.mainframe);
        fl.removeAllViews();
        FragmentTransaction transaction1 = getSupportFragmentManager().beginTransaction();
        transaction1.add(R.id.mainframe, fr);
        transaction1.commit();
    }
    

提交回复
热议问题