To make a free experience, ViewPager not only downloads the view you are viewing, but also adjacent views. This means that if you scroll from position 0 to position 1, then what actually happens is that position 2 loads, so it will be ready when you scroll. This is why the change applies to the "next" view, and not to the current one (if you scroll from view 2 to 1, then view 0 is created).
Since you set the static LinearLayout to OnCreate, then only the last view is created, which will be changed, and it will only ever be that you look at if you scroll to the end of the pager. Instead, you should keep track of which fragment the user is viewing (ViewPager.setOnPageChangeListener ()) and cache the fragment in your adapter. Then you know what position of the fragment you want, and when you ask for it, you simply return the one you created earlier (do not create a new one, then it will not work :)).
Or, tl version; dr: LL_Head is almost always set as the next fragment, not the current one. Do not put it statically. Download it to your PagerAdapter and configure it when you need it.
Edit: Alternatively, you might want the snippets to listen to a random event that tells them whether they should show or hide the layout in question. Otherwise, it will be only the current fragment, which is affected by this, and not all fragments.
source share