Android: fragments overlapping issue

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

    It all has to do with the engineering behind the replace and the addToBackStack methods.

    The replace method will actually do two things. Hide the existing fragment (let's say A) and add a new one (let's say B) in the container.

    Adding that transaction to the back stack will do the opposite. Remove B and add A.

    So, the solution to your problem is
    1. use addToBackStack method.
    2. make sure that the reverse replacement of fragments is the correct order

    The second suggestion is really important, because it is pretty often that at some point the current fragment is not removed and another one is added, which causes the two fragments showing at the same time.

提交回复
热议问题