Android: fragments overlapping issue

前端 未结 17 1298
闹比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:03

    Did you check your XML and see if the main layout is Frame Layout? If not then, use the Frame Layout instead. This will resolve overlapping issue. That's the only way to fix. I tried the "accepted" answer while searching for a solution for this problem and it didn't work.

    0 讨论(0)
  • 2020-11-27 18:03
    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();}
    
    0 讨论(0)
  • 2020-11-27 18:03

    Making the background color white solved it for me too. I think this is a bug or and implementation issue in the Android fragmentment manager. I was implementing my replace and popBackStack() correctly.

    0 讨论(0)
  • 2020-11-27 18:03

    Instead of using fragment as the container for the fragments, use FragmentContainerView. That solved the issue for me

    0 讨论(0)
  • 2020-11-27 18:05

    fragment manager maintains the stack of all the previous fragments that are replaced sometimes the back stack fragments overlaps with the fragment we replaced, for me

      fragmentManager.popBackStack(); 
    

    works, we can do this in a loop too to pop all the fragments in the stack hope it helps, Thanks. Happy Coding :)

    0 讨论(0)
  • 2020-11-27 18:06

    This is how I fixed it ..

    Setting the background would remove the overlapping effect from the screen only if the layout is matched to fill screen

    New fragments replaced on button clicks were not getting replaced on tab_selected or tab change action

    following code fixed it for me

        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        // This is required since button click replaces fragment whose link is lost hence overlapping isuee was occuring
        ft.replace(android.R.id.content, mFragment); 
        // On Tab Change remove old fragment views
        ft.remove(mFragment);
    }
    
    0 讨论(0)
提交回复
热议问题