Hey,
Sometimes fragment tabs are just pain.. They just reload each tab changes and it causes the lag and screen frozen. Fortunately, solution is simple :)
Markdown:
int limit = (mSectionsPagerAdapter.getCount() > 1 ? mSectionsPagerAdapter.getCount() - 1 : 1);
mViewPager.setOffscreenPageLimit(limit);
Gist:
/* DO NOT FORGET! The ViewPager requires at least “1” minimum OffscreenPageLimit */ int limit = (mSectionsPagerAdapter.getCount() > 1 ? mSectionsPagerAdapter.getCount() - 1 : 1); mViewPager.setOffscreenPageLimit(limit);
We just set the setOffscreenPageLimit through the ViewPager..DO NOT FORGET! The ViewPager requires at least “1” minimum OffscreenPageLimit.The limit variable algorithm is simple. That’s it :)Have fun, If you have any question, ask me !