Android Tablayout Prevent Activation Of Tabs Adjacent To Selected
Solution 1:
The reason this is happening is due to you using a ViewPager.
ViewPager, by default, will auto-create the adjacent Fragments because this allows the user to swipe to them whenever they wish. Creating them only when they're ready to swipe might cause lag or some unpleasant visual effects.
ViewPager has a method called setOffscreenPageLimit(int limit)
which can limit the amount of adjacent it keeps in memory, however I believe it's not possible to decrease it to 0 due to ViewPager's innate behavior.
If you've already disabled swiping between tabs, then it sounds like what you want isn't a ViewPager. Consider just using FragmentTransactions to replace the active Fragment.
Solution 2:
viewPager.setOffscreenPageLimit(0)
is what you are looking for. But a ViewPager doesn't allow offscreen limit less than 1.
Use something else than a viewPager to get your desired effect. One way of doing it without viewPager would be to have a frameLayout instead and inflate a new fragment and destroy the previous one when a tab is selected.
Post a Comment for "Android Tablayout Prevent Activation Of Tabs Adjacent To Selected"